Access field data in views row template (views 3) So I checked Google for the past 2 hours because apparently something that was fairly simple back in the Views 2 days has changed in Views 3 (D7)... All attempts failed.

I have a view set to display as HTML list showing fields. One of those fields is an image field. I want to use the URL to the image file as inline style background-image on the LI element of the particular row.

In Views 2 I would have set the field to be excluded from display and then created a views template for the row and then used the $row variable to access the field information for the particular row. In Views 3 there only seems to be the $title and $options variable available and $row outputs only the rendered HTML for the whole row.

Long story short: How can I access the field data from inside a views-view-list--myview--page.tpl.php?

If anyone can help out, it is greatly appreciated.
This is pretty simple. All you need to do is go through following steps, which will let you create a same type of view which I have created on my system: The trick is to use relationship from field_image.


Create a simple view of articles (I created page), by default this will have a field_image. I am exporting a view below, import it.
In theme information override style output from "views-view-list.tpl.php". I am attaching code for both. 


View: 

$view = new view();
$view-&gt;name = 'article_view';
$view-&gt;description = '';
$view-&gt;tag = 'default';
$view-&gt;base_table = 'node';
$view-&gt;human_name = 'Article View';
$view-&gt;core = 7;
$view-&gt;api_version = '3.0';
$view-&gt;disabled = FALSE; /* Edit this to true to make a default view disabled initially */

/* Display: Master */
$handler = $view-&gt;new_display('default', 'Master', 'default');
$handler-&gt;display-&gt;display_options['title'] = 'Article View';
$handler-&gt;display-&gt;display_options['use_more_always'] = FALSE;
$handler-&gt;display-&gt;display_options['access']['type'] = 'perm';
$handler-&gt;display-&gt;display_options['cache']['type'] = 'none';
$handler-&gt;display-&gt;display_options['query']['type'] = 'views_query';
$handler-&gt;display-&gt;display_options['exposed_form']['type'] = 'basic';
$handler-&gt;display-&gt;display_options['pager']['type'] = 'full';
$handler-&gt;display-&gt;display_options['pager']['options']['items_per_page'] = '10';
$handler-&gt;display-&gt;display_options['style_plugin'] = 'list';
$handler-&gt;display-&gt;display_options['row_plugin'] = 'fields';
$handler-&gt;display-&gt;display_options['row_options']['default_field_elements'] = FALSE;
/* Relationship: Content: Image (field_image:fid) */
$handler-&gt;display-&gt;display_options['relationships']['field_image_fid']['id'] = 'field_image_fid';
$handler-&gt;display-&gt;display_options['relationships']['field_image_fid']['table'] = 'field_data_field_image';
$handler-&gt;display-&gt;display_options['relationships']['field_image_fid']['field'] = 'field_image_fid';
/* Field: Content: Title */
$handler-&gt;display-&gt;display_options['fields']['title']['id'] = 'title';
$handler-&gt;display-&gt;display_options['fields']['title']['table'] = 'node';
$handler-&gt;display-&gt;display_options['fields']['title']['field'] = 'title';
$handler-&gt;display-&gt;display_options['fields']['title']['label'] = '';
$handler-&gt;display-&gt;display_options['fields']['title']['alter']['word_boundary'] = FALSE;
$handler-&gt;display-&gt;display_options['fields']['title']['alter']['ellipsis'] = FALSE;
$handler-&gt;display-&gt;display_options['fields']['title']['element_label_colon'] = FALSE;
/* Field: File: Path */
$handler-&gt;display-&gt;display_options['fields']['uri']['id'] = 'uri';
$handler-&gt;display-&gt;display_options['fields']['uri']['table'] = 'file_managed';
$handler-&gt;display-&gt;display_options['fields']['uri']['field'] = 'uri';
$handler-&gt;display-&gt;display_options['fields']['uri']['relationship'] = 'field_image_fid';
$handler-&gt;display-&gt;display_options['fields']['uri']['label'] = '';
$handler-&gt;display-&gt;display_options['fields']['uri']['element_label_colon'] = FALSE;
/* Sort criterion: Content: Post date */
$handler-&gt;display-&gt;display_options['sorts']['created']['id'] = 'created';
$handler-&gt;display-&gt;display_options['sorts']['created']['table'] = 'node';
$handler-&gt;display-&gt;display_options['sorts']['created']['field'] = 'created';
$handler-&gt;display-&gt;display_options['sorts']['created']['order'] = 'DESC';
/* Filter criterion: Content: Published */
$handler-&gt;display-&gt;display_options['filters']['status']['id'] = 'status';
$handler-&gt;display-&gt;display_options['filters']['status']['table'] = 'node';
$handler-&gt;display-&gt;display_options['filters']['status']['field'] = 'status';
$handler-&gt;display-&gt;display_options['filters']['status']['value'] = 1;
$handler-&gt;display-&gt;display_options['filters']['status']['group'] = 1;
$handler-&gt;display-&gt;display_options['filters']['status']['expose']['operator'] = FALSE;
/* Filter criterion: Content: Type */
$handler-&gt;display-&gt;display_options['filters']['type']['id'] = 'type';
$handler-&gt;display-&gt;display_options['filters']['type']['table'] = 'node';
$handler-&gt;display-&gt;display_options['filters']['type']['field'] = 'type';
$handler-&gt;display-&gt;display_options['filters']['type']['value'] = array(
  'article' =&gt; 'article',
);

/* Display: Article List */
$handler = $view-&gt;new_display('page', 'Article List', 'article_list');
$handler-&gt;display-&gt;display_options['path'] = 'article-view';


Now the overridden template:

&lt;?php

/**
 * @file
 * Default simple view template to display a list of rows.
 *
 * - $title : The title of this group of rows.  May be empty.
 * - $options['type'] will either be ul or ol.
 * @ingroup views_templates
 */

?&gt;
&lt;?php print $wrapper_prefix; ?&gt;
  &lt;?php if (!empty($title)) : ?&gt;
    &lt;h3&gt;&lt;?php print $title; ?&gt;&lt;/h3&gt;
  &lt;?php endif; ?&gt;
  &lt;?php print $list_type_prefix; ?&gt;
    &lt;?php foreach ($rows as $id =&gt; $row): ?&gt;
      &lt;li class="&lt;?php print $classes_array[$id]; ?&gt;" style="background-image:url(&lt;?php print file_create_url($view-&gt;result[$id]-&gt;file_managed_field_data_field_image_uri); ?&gt;);"&gt;&lt;?php print $row; ?&gt;&lt;/li&gt;
    &lt;?php endforeach; ?&gt;
  &lt;?php print $list_type_suffix; ?&gt;
&lt;?php print $wrapper_suffix; ?&gt;


This will do the trick for you. Let me know if you face some issues.