I have a view, displaying in a block, with a views-view--VIEWNAME--block-1.tpl.php:

<div class="X">
        print render($title_prefix);
        if ($title): print $title; endif;
        print render($title_suffix); 
    ...some view content...

Most of the content in this template has been copied straight from the template given by theme => information => display template in the view settings.

This displays (with some whitespace differences):

<section id="block-views-VIEWNAME-block-1" class="block block-views">
    <h2>BLOCK TITLE</h2>
    <div class="content">
        <div class="X">
    ...some view content...

Why is the view not displaying the view title inside the <h2>? The title is definitely set for the view.

I've put the following code in the view template:

print print_r(array_keys(get_defined_vars()), 1);

And the result (including "title" at index 30) is:

    [0] => template_file
    [1] => variables
    [2] => view
    [3] => view_array
    [4] => theme_hook_suggestion
    [5] => theme_hook_suggestions
    [6] => zebra
    [7] => id
    [8] => directory
    [9] => classes_array
    [10] => attributes_array
    [11] => title_attributes_array
    [12] => content_attributes_array
    [13] => title_prefix
    [14] => title_suffix
    [15] => user
    [16] => db_is_active
    [17] => is_admin
    [18] => logged_in
    [19] => is_front
    [20] => rows
    [21] => css_name
    [22] => name
    [23] => display_id
    [24] => header
    [25] => footer
    [26] => exposed
    [27] => more
    [28] => feed_icon
    [29] => pager
    [30] => title
    [31] => attachment_before
    [32] => attachment_after
    [33] => dom_id
    [34] => classes
    [35] => attributes
    [36] => title_attributes
    [37] => content_attributes

2 Answers 2


Just had the same problem on another site: for some reason the view title ($handler->display->display_options['title'] = 'Blogs';) was coming out in the page.tpl.php template $title, but not in the views-view.tpl.php $title (despite the default template for that page suggesting that it should). Possibly the variable gets undefined after it's used in an "earlier" template? Or maybe the title variable is only set for the view template if the view is being rendered as a block, on the assumption that the page template has already printed the title for the page?

Anyway, the solution is just to do the printing in the page.tpl.php right before rendering the page content (which will likely come from either the node template or a view depending on the page):

<h1><?php print $title; ?></h1> <!-- either our view title or our node title -->
<?php print render($page['content']); ?>

Of course if you're doing this you need to make sure not to print the $title variable out in the node template because if you do that you'll have the title printing twice.


Based on:

if ($title): print $title; endif;

and that you say that

is empty suggest that $title does not have a value.

Take a look at the handbook page "Views 2 theming". There's a section called "Step 4: Identifying Your Template Variables" which outlines how to get a listing of the variables currently defined. You'll need to confirm that $title is defined.

print print_r(array_keys(get_defined_vars()), 1);
  // If you have devel.module installed, comment the line above and uncomment the line below
  // dsm(array_keys(get_defined_vars()));

Each array key is the name of a variable, so an array key named "foo" could be inserted into the template as:

print $foo;

If $title is not defined you'll have to dig deeper. Please check back and let us know what you find. We'll help go further in finding $title if you don't have any luck.

  • Thanks for looking at this @DeeZone. I've printed out the defined vars as you suggested (results above in the original q) and the title is in there at index 30 - so I'm assuming that it's defined, but empty?
    – George
    Oct 14, 2011 at 4:22
  • Nice, so at least $title is defined but based on: if ($title): print $title; endif; it's empty. As a next step try outputing some of the other varables that have been define, print_r($title_attributes_array) looks like it might be a possible place to look. Keep poking, it's in there somewhere.
    – DeeZone
    Oct 19, 2011 at 1:29

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.