2

For a node listing on a taxonomy term page, like:

taxonomy/term/4

It's currently using the node template I set up just for when you are looking at a node:

node--spot.tpl.php

I added this code to hook_preprocess_node:

if(arg(0) == 'taxonomy') {
  array_push($vars['theme_hook_suggestions'], 'node_taxonomy');
}

The node template file name I want to use is:

node-taxonomy.tpl.php

I confirmed the hook is running but it's still using:

node--spot.tpl.php

What am I doing wrong?

Update 1: According to the source code theme_hook_suggestions are listed in reverse priority order, so I changed array_unshift to array_push.

Update 2: I am correctly seeing in Devel themer that my template should be used first, even when it isn't:

node_taxonomy < node_14 < node_spot < sites/all/themes/hotness/templates/node--spot.tpl.php

0

2 Answers 2

6

This answer had two parts:

  1. As detailed in my Update #1, you have to put your suggestion last in the theme_hook_suggestions array, as last is highest priority.

  2. Your template files must be named with two dashes, not one.

File system:

node--taxonomy.tpl.php

As added to theme_hook_suggestions array:

node__taxonomy

-1

Actually there is $variables['theme_hook_suggestions'] in hook_preprocess_node, $vars is in hook_preprocess_page I guess.

1
  • It is totally up to you how do you want to name the variable $variables oder $vars, it doesn't matter.
    – Elin Y.
    Commented Dec 28, 2013 at 23:22

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.