I know that I can use this template:
block--views--home-slides-block.tpl.php
to print / render my slideshow:
<div id="banner_area-vs">
<?php echo views_embed_view('home_slides_new', 'block'); ?>
</div>
But what if I wanted to only render a particular field from the slideshow View?
I looked at the Theme Information details within the Slideshow View,
and it suggested the following (see screenshot):
So I created this template:
views-view-field--field-slideshow-image.tpl.php
but now I am unsure how to render/print the specific field ?
Comments
in the directory "core/modules/views/templates"
you'll find the file "views-view-field.tpl.php"
This is a generic file for the output of a single field and the description should help you for your specific need.
Is this what you need?
I'm not sure.
I used the example from that file, e.g. this:
and I changed it to this:
I inserted that code into a file (used Theme Debug for suggested file name):
block--views--home-intro-view-block.tpl.php
That file only has this in it:
<?php
print $data = $view->{$field->field_intro_image};
?>
THe "field_intro_image" text within that code I grabbed from Content Type / Home Intro / Manage Fields (machine name for that field).
But now, nothing is showing. i.e. the Home Intro Title, Text and Image used to display.
But now since making that tpl.php file with that code in it, none of those fields are showing anymore.
What have I done wrong?
Maybe there is somebody more qualified to help you. Because I don't use tpl-files so often and try to avoid using code whenever possible.
I propose another approach:
Create a view (as a block) that gives you exactly what you need and place it then there where you need it. I do it for example with hero-images most of the time like this.
Use a contextual filter to get the image of the node you're viewing.
Here is a short video that shows how to do it. It's an example from Drupal 8 but creating the view is almost the same.
http://mustardseedmedia.com/podcast/episode59
You can then place the block in the layout.
This is the way I would solve the problem... without tpl-files.
Try this (ie. removing the `$data = ` portion):
I tried that new code you suggested, i.e. this:
but no fields show up.
If I rename the page from this:
block--views--home-intro-view-block.tpl.php
to this:
block--views--home-intro-view-block.tpl.php
and then clear my Cache, then all the Views fields appear again.
I'm hoping I can figure out how to render/print each field individually though as I need to style them in ways that the class options within Views is not giving me access to.
Those file names look identical to me -- what is the difference?
Sorry I had a type in that last response.
What I meant to say is that I renamed the template file to a 'wrong' name (.e.g so it couldn't be detected) and all the fields display, albeit not how I want them to.
As in, without the template in use, the fields are there.
With the template in place, no fields display at all.
To reiterate, what I'm attempting to do is render individual fields throughout the template so I can wrap various div classes around each individual field.
I tried achieving this via the suggested code you commented to me, but that caused all fields to disappear.
If you have any other suggestions it would be appreciated.
Cheers
@laryn any idea why that one didn't work?