1

I'm a bit confused about how to name my template files. It's the first time I started to mess with templates in drupal 7 and somehow I don't get it.

I want a template file that changes the behavior of my blog posts which are on my front page. In Drupal 6 a file named node-blog.tpl.php was all I needed to mess with my blog posts.

I tried the same with Drupal 7, but it didn't work. I searched for an answer and read that the following function should be relevant for choosing the template files.

function template_preprocess_node(&$variables) {
  ...
// Clean up name so there are no underscores.
  $variables['theme_hook_suggestions'][] = 'node__' . $node->type;
  $variables['theme_hook_suggestions'][] = 'node__' . $node->nid;
}

I also read about some conversion between '-' and '_' because '-' could not be used in function names. So I tried a few variants.

node__blog.tpl.php
node--blog.tpl.php
node-blog.tpl.php
node_blog.tpl.php

None of them is recognised by Drupal. What am I doing wrong?

1

The following should work:

node--blog.tpl.php

Make sure that you also have a node.tpl.php in your theme folder and that you cleared the cache.

See also Page template suggestions are not working for more information.

  • Hm ok, I got the node.tpl.php in my theme folder and named my theme-file right. If this is all correct I have to look somewhere else for my problems. Thx. – mantuko Apr 29 '11 at 17:59
  • It was a caching problem. It wasn't enough to disable 'Cache pages for anonymous users' and 'Cache blocks'. I had to hit 'clear all caches' to make it work. That happens if you search for a problem at the wrong place ;-) – mantuko Apr 29 '11 at 18:06
  • Yes, there are many caches (even more in Drupal 7 than 6) which are always cached, although there are way to disable these caches during development. But then it will take significantly more time and resources for each page to display. See drupal.stackexchange.com/questions/100/… for more information – Berdir Apr 29 '11 at 18:47
0

Glad you got away from adding custom suggestions!

Only time that's a good thing is if you want to run several node types through the same alternate node template.

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.