I know that I can use this template:


to print / render my slideshow:

<div id="banner_area-vs">

<?php echo views_embed_view('home_slides_new', 'block'); ?>



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:


but now I am unsure how to render/print the specific field ?



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. 

 * @file
 * This template is used to print a single field in a view.
 * It is not actually used in default Views, as this is registered as a theme
 * function which has better performance. For single overrides, the template is
 * perfectly okay.
 * Variables available:
 * - $view: The view object
 * - $field: The field handler object that can process the input
 * - $row: The raw SQL result that can be used
 * - $output: The processed output that will normally be used.
 * When fetching output from the $row, this construct should be used:
 * $data = $row->{$field->field_alias}
 * The above will guarantee that you'll always get the correct data,
 * regardless of any changes in the aliasing that might happen if
 * the view is modified.
<?php print $output; ?>

Is this what you need?

I'm not sure.

I used the example from that file, e.g. this:

$data = $row->{$field->field_alias}

and I changed it to this:

$data = $view->{$field->field_intro_image};

I inserted that code into a file (used Theme Debug for suggested file name):


That file only has this in it:


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. 


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):

<?php print $view->{$field->field_intro_image}; ?>

I tried that new code you suggested, i.e. this:

print $view->{$field->field_intro_image};

but no fields show up.

If I rename the page from this:



to this:


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.


@laryn any idea why that one didn't work?