theme node by id (node-1.tpl.php)

CoolCow - July 3, 2009 - 14:49

Hello everyone,

I want to theme a nodes by it's ID.
In other words i would like to create template files like node-1.tpl.php, node-2.tpl.php, ...

Trying to do this i defined the theme preprocess function like this:

<?php
function THEME_NAME_preprocess(&$variables, $hook) {
    switch(
$hook) {
        case
'node':
           
$variables['template_files'][] = 'node-' . $variables['nid'];
        break;
    }
    return
$variables;
}
?>

But this doesn't work.

I've been searching around in the theme.inc file to understand the steps drupal goes trough in choosing the template file.

The only thing i've found is that drupal only looks in the "modules/node" directory for that file and not in my theme directory.

Now my question is:
How can i tell drupal to look in the theme directory for that file?

This            

nevets - July 3, 2009 - 14:59

This

            $variables['template_files'][] = 'node-' . $variables['nid'];

should be
            $node = $variables['node'];
            $variables['template_files'][] = 'node-' . $node->nid;

Tried it, but doesn't make a

CoolCow - July 3, 2009 - 15:21

Tried it, but doesn't make a difference.

 
 

Drupal is a registered trademark of Dries Buytaert.