1

On Drupal 7, I am trying to create a different version of the default taxonomy template file for a theme. When a user clicks on a taxonomy term, the new template file is used instead of the default one.

So far all I have managed to do is finding the correct template file name (page--taxonomy.tpl.php). The problem that I have is that the variables copied from the template file the Taxonomy module uses simply don't work, as they are obviously not being populated.

<?php if ($content = render($page['content'])): ?>
  <div id="taxonomy-term-<?php print $term->tid; ?>" class="<?php print $classes.' channels-'.strtolower(str_replace(' ','',$term_name)); ?>">
    <?php if (!$page): ?>
      <h2><a href="<?php print $term_url; ?>"><?php print $term_name; ?></a></h2>
    <?php endif; ?>
    <div class="content">
      <?php print render($content); ?>
    </div>
  </div>
<?php endif; ?>

So any variable beginning with $term is NULL. What/where do I call to populate these?

1

The only template file used from the Taxonomy module is the taxonomy-term.tpl.php file. If a theme implement that template file, it receive the following variables. (The list is partial; for the complete list see the documentation.)

  • $term_url: Direct URL of the current term
  • $term_name: Name of the current term
  • $term: Full term object

page--taxonomy.tpl.php is a page template that Drupal uses for pages with a URL matching taxonomy/*. It is a page template, for which the variables are different. In particular, it doesn't get any $term* variable.

References

  • Many thanks! That makes sense; I rename my template file taxonomy-term.tpl.php, and clear cache, and away it goes. Cheers! – Onyx Nov 4 '12 at 9:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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