views:

115

answers:

3

The standard template for a node in Drupal is node.tpl.php

It's possible to call a different template for a content-type, like 'newsitem'. You will call it like this : node-newsitem.tpl.php.

I was wondering if there's a way to call a specific Node ID? node-34.tpl.php does not work.

Thanks

+2  A: 

In your theme's template.php put the following at the top of theme_preprocess_node():
$vars['template_files'][] = 'node-'. $vars['node']->nid;

So if your theme is called "myTheme", you might have the following:

function myTheme_preprocess_node(&$vars){  
    $vars['template_files'][] = 'node-'. $vars['node']->nid;  
}
Aaron
A: 

That naming convention will work, just not by default. Assuming this is Drupal 6, try adding the following code to your theme's template.php:

/**
* Override or insert variables into the node templates.
*
* @param $vars
*   An array of variables to pass to the theme template.
* @param $hook
*   The name of the template being rendered ("node" in this case.)
*/
function yourthemename_preprocess_node(&$vars, $hook) {
  $node = $vars['node'];
  $vars['template_file'] = 'node-'. $node->nid;
}

Make sure you don't try to redeclare yourthemename_preprocess_node()--that is, if it already exists in your theme's template.php, just add the $node and $vars['template_file'] lines to it.

peterjmag
A: 

I have this working as we speak. In Drupal 6, my front page is node 5. It uses

page-node-5.tpl.php

If it's not loading, consider clearing cache's or rebuilding your theme registry.

Chris Ridenour
page-node-5.tpl.php is a variant of page.tpl.php, the OP is looking to create variants of node.tpl.php
Aaron
Sure, but newsitem-node-34.tpl.php would accomplish the same thing.
Chris Ridenour
I don't follow you. newsitem-node-34.tpl.php doesn't follow any type of template suggestion pattern in drupal 6 that I'm familiar with.
Aaron
I'm having trouble finding the d.o article I found it on, but I assure you it's working. And I couldn't find any additional templates added in Fusion, so I'm not sure!
Chris Ridenour