Skip to content

Instantly share code, notes, and snippets.

@zachwood
Created May 14, 2010 17:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zachwood/401388 to your computer and use it in GitHub Desktop.
Save zachwood/401388 to your computer and use it in GitHub Desktop.
/**
* Determine node template overwrites
*
* @param array $vars
* @param string $hook
*/
function THEME-NAME_preprocess_node(&$vars, $hook) {
switch ($hook) {
case 'node':
// Here is the way to switch to a different node- template based on node properties.
if ($vars['page']) {
// This is LIFO (Last In First Out) so put them in reverse order, i.e
// most important last.
$vars['template_files'] = array(
'node-default-page',
'node-'. $vars['node']->nid,
'node-type-'. $vars['node']->type,
'node-'. $vars['node']->path,
);
}
elseif ($vars['node']->type) {
$vars['template_files'] = array(
sprintf('node-type-%s', $vars['node']->type),
);
}
else {
$vars['template_files'] = array(
sprintf('node-%s', $vars['node']->nid),
);
}
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment