Theme suggestions for teasers
Published by emacstheviking on Sat, 05/14/2011 - 12:53
After reading:
http://bri-space.com/content/template-suggestions-drupal-7-themehooksuggestions#comment-43
and leaving some comments I thought I'd summarize it here too for my own benefit. My real purpose of my blog is so *I* don't forget where I put stuff that I found useful, you'll notice it's infrequently updated and pretty crap looking. So is my brain! LMFAO.
Situation: doing a template for a custom node type and I didn't want to bloat the node--type.tpl.php file with an if ($teaser)...
Solution: Add a template suggestion so that I can split them out a.k.a 'separation of concerns' even for themes, why not!
Code:
function wolfrock_theme_preprocess_node(&$vars, $hook)
{
if($vars['teaser']) {
$vars['theme_hook_suggestions'][] = 'node__'.$vars['node']->type.'_teaser';
$vars['theme_hook_suggestions'][] = 'node__'.$vars['node']->nid.'_teaser';
}
}
Works for me! :)
Add new comment