I am subtheming the adaptive-theme base drupal 7 theme. I've create a template called node--article.tpl.php that I would like rendered for articles, with all the rest of the node types rendered with node.tpl.php. The node--article.tpl.php is never used, only node.tpl.php in the same directory.

I have also tried adding the following to template.php in the subtheme to no effect.

function mytheme_preprocess_node(&$variables) {
$variables['theme_hook_suggestions'][] = 'node__'. $variables['node']->type;
}

What am I doing wrong?

Thanks

Comments

emmajane’s picture

Try renaming the file to have only one dash: node-contenttype.tpl.php.

More about template naming suggestions at: http://drupal.org/node/190815

Jeff Burnz’s picture

Actually the template name is correct -- in D7 we now use 2 hyphens for template suggestions, so node--article.tpl.php is correct.

You don't need to add anything special to the theme to get suggestions to work, core is taking care of that for you already. Also, in D7 you no longer need the root template (such as node.tpl.php) in the same directory, that old D6 bug has been squashed.

You probably need to rebuild the theme registry so Drupal knows about the new template - go to the Performance settings and clear the cache.

If you are doing some hard core dev you might want to install the Devel module, which has a setting that rebuilds the registry on every page load - very useful.

Hope you're enjoying that HMTL5 goodness :)