Community

Drupal 7: Views template files not outputting content

I have a views called news, it has two views template files:

  • views-view-fields--news--page-1.tpl.php
  • views-view--news--page-1.tpl.php

I am able to customize the output for views-view-fields--page-1.tpl.php. However, when I try to customize views-view--news--page-1.tpl.php, nothing gets outputted to the browser. I've tried the following in views-view--news--page-1.tpl.php:

<div>hello</div> (#1)
<?php print $header; ?> (#2)
<?php print $variables->header; ?> (#3)

I am puzzled why putting (#1) the template file doesn't output anything. So I attempted:

<?php dsm($variables); ?> (#4)

Luckily, devel was kind enough to output what variables I am able to play with in views-view--news--page-1.tpl.php. Among the variables were the string values (immediate children in the $variables array):

  • header (#5)
  • rows (#6)

Because (#5) and (#6) are immediate children in the $variables array, I'm not sure why trying to print them outputs nothing (as attempted in (#2) and (#3)). I've tried to flush all cache, as well as flush theme cache anytime I modify anything in the views template files.

Comments

Are they arrays (vs strings)?

Are they arrays (vs strings)?

Both are string

According the dsm($variables), header, and rows are 'string' type in the $variables array.

I am pretty sure they are

I am pretty sure they are both arrays (positive about rows since it rows of data to output).

Variables is an array with 27

$variables is an array with 27 elements. The first level elements (in the array) include:

  • rows (String, 2764 characters )
    •   <div class="views-row views-row-1 views-row-odd views-row-first">
          <div class="news">
            <div class="news-label"></div>
            <div class="news-details">
              <span>other half</span>
            </div>
            <br class="clear" />
          </div>
        </div>
        <div class="views-row views-row-2 views-row-even">
          <div class="news">
            <div class="news-label"> </div>
            <div class="news-details"> <span>other half</span> </div>
            <br class="clear" />
          </div>
        </div>
  • header (String, 25 characters )
    • <h2>Upcoming News</h2>

As you mention $variables is

As you mention $variables is an array, try printing $variables['header']
But it looks like something is strange. Did you copy the base template(with comments) or created new one?

// Ayesh

Ayesh, I created a blank

Ayesh, I created a blank template file using 'dreamweaver' - called 'views-view--news--page.tpl.php'. The contents currently are:

<?php dsm($variables); ?>

<div>Nothing works here</div>

<?php print $variables->header; print $variables['header']; print $header; print $variables->$header; ?>

However, the only thing that prints (displays on the browser), is the

<?php
dsm
($variables);
?>
output.

I also tried the following in

I also tried the following in 'views-view--news--page.tpl.php':

<?php print render($variables['header']); print render($header); ?>

Views theming information

If I goto Events page: Theming information on: '[site:name]/test/admin/structure/views/view/events',

I can see the following in bold:

Display Output: views-view--news--page.tpl.php
Style output: views-view-unformatted.tpl.php
Row style output: views-view-fields--news--page-1.tpl.php
Field Content: Title (ID: title): views-view-field.tpl.php

nobody click here