Created
May 14, 2010 17:15
-
-
Save zachwood/401388 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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