I want to create a simple php template for Views in Drupal 7, but I think I'm missing a crucial element to this puzzle, as every time I try to get to the content of Views' output in the template's php code, even if I use the default views-view.tpl.php file as a template for that particular view, I get

Undefined variable: fields in include() ...

How do I get around this?

4 Answers 4


How is your override requirement? Is it for all the views or for a certain views?

For certain views: In that views admin page : go to Advanced -> Theme: Click on Information

you will see the active templates for 'Display output' in bold (views-view.tpl.php) and rest available theme suggestions for overridden (comma separated).

Now copy views-view.tpl.php from views contrib module theme folder and put it in your site theme folder, rename it to one of the name suggestion available in views. Make changes to your template.

Clear cache and check.


Have you tried with this format views-view--content type--page.tpl.php ?


create the view page in block type

put code like this in template file

if(arg(0) == 'user-favorites'){
  $variables['theme_hook_suggestions'][] = 'page__favorites';

create tpl page name like this page--favorites.tpl

and render the block content like this

   $deal_block = module_invoke('views','block_view','user_favourites-block_5');
   print '<h2 class="block-title">title</h2>';
   print render($deal_block['content']);

Simple answer is there is no variable $fields in the views-view.tpl.php.

You'll need to work with the $rows or the $view variables.


In addition to what @Jeet said:

It's important to understand how Views theming works. There is not simply one views template; views are themed with a chain of nested templates.

The first template is like a wrapper around the view, displaying title, header, footer, etc.

The second template depends on the view style you choose (list, table, grid, etc.).

Most views styles then use a third template for the row style. This contains the html that is repeated for each result.

Some views even have more templates, for instance for the separate fields within a row.

On every level you can override every template in multiple ways, by adding a template file with the correct name in your theme folder. All possible template file names are listed under advanced -> theme -> information. These templates range from generic (applies to all views) to specific (applies to a specific display of a specific view).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.