Theme suggestions for teasers

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! :)

Content Tags: 

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <pre> <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Syntax highlight code surrounded by the {syntaxhighlighter SPEC}...{/syntaxhighlighter} tags, where SPEC is a Syntaxhighlighter options string or class="OPTIONS" [title="the title"].
  • Lines and paragraphs break automatically.

Full HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • Syntax highlight code surrounded by the {syntaxhighlighter SPEC}...{/syntaxhighlighter} tags, where SPEC is a Syntaxhighlighter options string or class="OPTIONS" [title="the title"].
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.