Last updated June 24, 2010. Created by gpk on April 16, 2007.
Edited by dooug, ronald_istos, Jeff Burnz, add1sun. Log in to edit this page.
If you want to use a specific node.tpl.php for a particular node, paste or merge this code into your template.php:
Drupal 6
<?php
function phptemplate_preprocess_node(&$vars) {
$vars['template_files'][] = 'node-' . $vars['nid'];
}
?>Drupal 4.7.x and Drupal 5.x
<?php
function _phptemplate_variables($hook, $vars = array()) {
switch ($hook) {
case 'node':
$vars['template_files'] = array('node-'. $vars['nid']);
break;
}
return $vars;
}
?>You can now use the template naming convention node-[nid].tpl.php such as node-34.tpl.php to create a custom node template for just the node 34.
Note that Drupal 7 out-of-the-box looks for node-specific templates, so you don't need to do anything to template.php.
Comments
Should be
[page-node-34.tpl.php] -- note the 'page-' on the front end.
The example works as
The example works as expected. No need to add the 'page-' on the front...
Drupal 7
Just a little tip for Drupal 7-users. It is enough to name the file node--[type|nodeid].tpl.php so in this example node--34.tpl.php
More infos here: http://drupal.org/node/177868