Posted by CoolCow on July 3, 2009 at 2:49pm
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?
Comments
This
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
Tried it, but doesn't make a difference.
There are some errors in
There are some errors in variables. The following code works.
template.php:
<?phpfunction phptemplate_preprocess(&$vars, $hook) {
switch ($hook){
case 'node':
$node_template = array_pop($vars['template_files']);
$vars['template_files'][] = 'node-' . $vars['node']->nid;
$vars['template_files'][] = $node_template;
break;
}
return $vars;
}
?>
...
Just use the specific function - template_preprocess_node...
<?phpfunction themename_preprocess_node(&$vars, $hook) {
$vars['template_files'][] = 'node-'.$vars['node']->nid;
}
?>
Responsive Drupal Themes | Drupal 8 Design Initiative | Certified to Rock