[Drupal][Solved] Missing taxonomy terms in a node view

| | 2 min read

We were working on a Drupal website which was handed to us by one of our Drupal clients. We were required to add a new content type to the Drupal site and create the associated views with it. While working on adding a feature we found that the taxonomy terms (tags) were not appearing on the node page of any content type. If you find that the tags have been missing then read on to know the most likely source of the issue.

An unmodified Drupal 6 site should display the taxonomy terms by default without any problems. The problem occurs if someone has customized the code in the site for something else. When we were handed the problem, our immediate instinct was to inspect the currently active theme of the website.

Now Drupal 6 uses the <pre><code>node.tpl.php</code></pre> file for displaying the content in the website. The template file is nothing but a php file with a mix of HTML markup and PHP variables. For a complete list of the PHP variables used by a Drupal 6 website have a look at

Drupal 6 Node template variables

The taxonomy terms are held by the <pre><code>$terms</code></pre>. Any modification to this printing of this variable will prevent the taxonomy terms from being printed on the site.

Coming back to the previous problem there was a indeed a condition added for the $terms variable from being printed on the site present in the node.tpl.php in a format similar to the one shown below

if($node->type == "abcd") {
       if ($taxonomy) {
        print $terms 
      }
    }

It seems there had been a requirement for the previous Drupal developer of the site to limit the taxonomy terms to nodes of a particular content type and he/she had added the code here. Although this is functionally correct the developer was mixing the logic with the theming which is not advisable.What if someone decides to change the node template file with a new template to change the design. This will make the designers job much harder. The correct way to do this to create a <pre><code>template.php</code></pre>>file within your theme and add the logic there. So even if the theme changes the we can simply copy the template.php file to the new theme.

Anyway coming back to the problem, if you have noticed that the taxonomy terms are missing in a Drupal site, be sure to checkout the the currently active theme and the node.tpl.php file or or the tpl file and see if there is any condition set to print the $terms variable. Newcomers to Drupal usually get stuck in such a scenario when the solution is so simple.