Johnny
Johnny

Reputation: 578

Different page templates for different nodes

Using drupal 7 is great. The api is full of great ideas - although I miss some OPP sometimes.

Now I stuck on a problem with defining different page templates for different nodes. After searching for this problem in the official documentation I found out that drupal uses suggestions to find templates like page-node-nid.tpl.php.

My Situation:

I have a page called "Skills" with the id 2. The url is /skills (don't know if this is important) and I have a template called /templates/page-node-2.tpl.php. But drupal doesn't load the file. I also try to rename the original page.tpl.php to see that I'm working in the right directory. Clearing the cache doesn't work either.

What am I doing wrong?

Hope you can help!
Thanks in advance!

Upvotes: 1

Views: 2659

Answers (2)

dzogchen
dzogchen

Reputation: 383

There seems to be an error in the documentation. try page--node--2.tpl.php Note that there are 2 dashes rather than 1

That works for me in Drupal 7

Upvotes: 4

Berdir
Berdir

Reputation: 6891

  • first, the alias (that is "skills in your case) isn't important
  • Where exactly is your template located? It needs to be in the top-level directory of your theme, not in a templates subfolder.
  • Not sure if that has been fixed in D7, but at least in D6, you also needed to have an page.tpl.php in your theme to have it pick up template suggestions?
  • After adding the file, make sure that you rebuild the theme registry, devel.module works well, or re-saving the form admin/build/themes.

Upvotes: 0

Related Questions