I want a specific "node.tpl.php" file to be used for a specific node. This particular node has to do all sorts of stuff, for which I need to write some significant PHP.
I've been doing some research, and I found that I can name a file "page-node-9.tpl.php," however, this overrides "page.tpl.php" which is not what I want. This overrides the entire page structure, where I just want to override the interior content section that's normally populated by "node.tpl.php".
I tried naming a file "node-node-9.tpl.php" but that didn't work.
(My understanding is that "node.tpl.php" effectively embeds itself into "page.tpl.php," correct? This being the case, "node.tpl.php" is the file I want to override for one single node.)
I could just do something like this in the "node.tpl.php" file --
if($node->nid ==0) { ... }
-- but that seems hack-ish.
Any ideas?
Comments
...
If the content type is 'abc' then the node template should be 'node-abc.tpl.php'.
No, a single node...
...not a content type. This node is a page, but I don't want override all pages, just node #9.
...
You mean a node of content type 'page'? Then you may copy 'node.tpl.php' to 'node-page.tpl.php' and hack the later.
Or you can use contemplate module.
In this case some hack is required. If you don't want to hard code '9' then use drupal function variable_get(). You have to call variable_set() first somewhere else.
What's wrong with an if statement?
Why not use an if statement as you had mentioned?
Maybe you can do an if statement which will call an include (.inc) file containing the changes that you want to make for the single node; this way you won't have to put all the code for that one node into node.tpl.php, just include it when needed.
It's just a thought.
ever find a way to do this ?
other than the hack ...
I've got a situation where I have a specific content type, but one of those nodes I need to appear differently.
i've tried (where type is my content type such as news, and nid is the # of the node such as 6751)
node-type-nid.tpl.php
and
node-nid.tpl.php
no dice.
You could add this to your
You could add this to your themes template.php file
changing "your_theme" to your themes actual name. This will allow template files of the form node-{nid}.tpl.php.
Note your theme may already implement hook_preprocess_node in which case the code should be added to the existing function.
[Fixed call to empty()]
I was loooking to do the same thing
@nevets
tried that snippet in Druapl 6 in my themes template.php as I thought preprocess is new to Drupal 6. Didn't work :(
still thinking...
jamie
At a glance, that preprocess
At a glance, that preprocess function does appear to work. I assume you did change "your_theme" to the name of your theme and emptied your drupal cache?
thanks for the reply -
thanks for the reply - 2things -
1. I was searching and found thins node in the theme guide drupal 6
http://drupal.org/node/190815
there is a snippet in the 2nd comment that i tried. Didn't work either.
2. emptied cache and it worked. Thanks for the heads up on drupal cache. I always thought just refreshing the browser did the trick.
u da man
Jamie
error in code above
As mentioned by nevets add this to hook_preprocess_node if it already exists or create a new function
In nevets code the if clause "! $empty" calls empty() as if its a variable not a function.
I have tested the above and it works my node shows the template node-81.tpl.php for instance .
Dave Shaw
I did it!
Hi, i use Multiflex3 theme and i just copied page.tpl.php to page-node-{your_nid_here}.tpl.php and i was able to have a custom template for a specific node.
My2Cents.
Something for Drupal 7.x
Drupal has provided a list of node suggestion type
Note: Don't forget "--" double hyphen and its not "-" single
Good luck