I need to make node.tpl.php aware when it's being viewed on a taxonomy page (not this is different from being viewed as a teaser).

I thought it would be simple to do stick in template.php:

mytheme__istax($hook, $vars) {
   switch($hook) {
     case 'node' :
      if (arg(0) == 'taxonomy' && arg(1) == 'term' && is_numeric(arg(2)) == '') {
        $vars = TRUE;
      }
        break;
   }
   return $vars;
}

And add in to node.tpl.php:

if $mytheme_istax == TRUE {
...

Yet this doesn't seem to work - node.tpl.php seems blissfully unaware. Could an experienced Drupal themer give some suggestions as to why this isn't working? Much appreciation from a non-coder - happy to repay the favour with some CSS tricks.

Comments

nevets’s picture

From what you provided it would appear you want

function yourtheme_preprocess_node(&$vars) {
  $vars['istax'] =  FALSE;
  if (arg(0) == 'taxonomy' && arg(1) == 'term' && is_numeric(arg(2)) == '') {
       $vars['istax'] =  TRUE;
  }
}

In node.tpl.php you could then use $istax.

Note you need to replace yourtheme with your themes name.

zhte’s picture

Wonderful, a perfect solution, and I am able to use your code example for many other things like /blog and /event too. Thank you!