Paul
Paul

Reputation: 858

using a specific node ID to call a template file

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

Upvotes: 0

Views: 9082

Answers (4)

Dmytro
Dmytro

Reputation: 5701

For Drupal 7 use this template name (34 - is node ID):

node--34.tpl.php

And don't forget to clear your cache! More information on drupal.org

Upvotes: 6

Chris Ridenour
Chris Ridenour

Reputation: 594

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.

Upvotes: 0

Aaron
Aaron

Reputation: 2689

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;  
}

Upvotes: 3

peterjmag
peterjmag

Reputation: 6179

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.

Upvotes: -1

Related Questions