As a themer, I spend ALOT of my time in the node.tpl.php (or node-custom.tpl.php) file doing layout. Often times, however, I'm not doing one layout in that file...but two: One for the full node, and one for the theme teaser (using if($page), etc...)

It would really clean up the node.tpl.php code alot if we could have a separate template for the teaser recognized out of the box. The idea would be that each node template could also be accompanied by a -teaser.tpl.php template where all teaser layout could be done. Of course, for those themers who wanted to continue doing both in the node.tpl.php they could keep doing that. But, by having this separate -teaser.tpl.php available, I know that it would clean up alot of theme code AND would be a way to do teasers that many more new themers would understand (right now, many folks don't even consider doing an if($teaser) and therefore don't know how to create a separate teaser layout).

So, to clarify: With this addition, we'd be able to use a node-teaser.tpl.php or a node-custom-teaser.tpl.php as a way to layout our teasers in their own template.


quick correction in paragraph one (sorry for the bad proofread):

One for the full node, and one for the TEASER....


I recently set this up on a site and there's a decision to be made: what takes precedence, teaser or node-type?
Ie, is it:




I would suggest that node-type takes precedent over node-type-teaser when looking for the teaser view (if that's what you're asking). Seems like that would be standard for the way all other template's flow.

My 2 cents.... node-type-state.tpl.php.

Be get node-type. The state part could be teaser, full, rss, or anything. I would default it to full. Thoughts?

Issue tags:+Needs design review

Issue tags:-Needs design review

mfer: Big +1 from a themer on #5

It makes sense, if we want organized template layouts, to organize by ANY state, not just teasers. I'd love to see the ability to drill down even further, for example: node-blog-teaser-front.tpl.php to theme front page teasers (would have to figure out the appropriate order, I suppose). Maybe pie in the sky, but that would ROCK.

Issue tags:+Needs design review

Issue tags:-Needs design review


I think that makes sense. And a node-type-rss.tpl.php file would override the setting for whether RSS feeds display full content or teasers.


Issue tags:+Needs design review

How does it map with #372743: Body and teaser as fields ?

Thanks @kika. We were looking for that issue and started that discussion just minutes after this theming idea came up while we were still at drupalcon.

Personally, I would prefer we work out a strategy here for what to do while body becomes a field (if that will happen in fairly quickly) and then make this change after that. Thoughts?

I do not believe that #396006: Addition of a node--teaser.tpl.php by default and #372743: Body and teaser as fields have anything to do with each other. A node has various fields and other module-provided content that render the same or differently on a teaser or full view. A site admin can change what renders how. A theme developer can build the node template (including a separate node teaser template) to show whatever subset of the available data that is desired.

Whether node's body and teaser come from Field API or from a special case inside node.module seems unrelated.

+1 on having a separate template for the teaser recognized out of the box. When I hear it articulated, I have the "Of Course that's how it should be" reaction. I realize that I often forget that it's not setup this way and start looking for the default teaser.tpl files before I remember that I need to insert conditional logic into my tpl file.

I hate teasers. Mostly because they're difficult to theme.

I assume we would also have template suggestions like node-teaser-NODETYPE.tpl.php?

+1, and it's about time! This will make logical sense to novice themers.

Status:Active» Postponed

Postponing until #372743: Body and teaser as fields goes in.

You might be interested in #409750: Overhaul and extend node build modes too...

Here is a really simple workaround. At the top of your node-CONTENTTYPE.tpl.php check if it is the page view or teaser view. Then include the appropriate file and return. Return in this case stops reading the current file.

if (!$page) {
  include path_to_theme() .'/node-CONTENTTYPE-teaser.tpl.php';

This is not just specific to content types, you could do this for the generic node.tpl.php as well.

Title:Addition of a node-teaser.tpl.php by defaultAddition of a node--teaser.tpl.php by default
Version:7.x-dev» 8.x-dev
Status:Postponed» Active

Michael, here's a much better way to do it in D6:

function mytheme_preprocess_node(&$vars) {
  if (!
$vars['page']) {
$vars['template_files'][] = 'node-'. $vars['node']->type .'--teaser';

Also, I think we missed the D7 deadline. :-)

In D7, you can add stuff to theme_hook_suggestions in preprocess functions. You would need to use the double-underscore convention.

['theme_hook_suggestions'][] == 'node__teaser';
would load a node--teaser.tpl.php file.

@#21 in D7 I do this:

function mytheme_preprocess_node(&$variables) {
$variables['theme_hook_suggestions'][] = 'node__' . $variables['type'] . '__' . $variables['view_mode'];

@morningtime Thank you, exactly what I needed. Very impressed at how easy it was to implement!

Another +1 from a novice themer. I actually assumed that this tpl existed and went looking for it, so this would make a lot more sense.

Check out the Display Suite Module for template suggestions specific to view modes.

Just a note on something to consider that bites me often: Just because something isn't a $page, doesn't mean it's a $teaser. For example, John's code in #20 would also theme Views displays that were "Full Node" displays, even though it's only intended to be a teaser (because $page doesn't exist in a views full page display).

I'm not sure what has/will change in D8 by the time this lands, but it would be good to ensure this determines "full node" vs. "teaser" in every sense (including when those options are chosen in Views or other displays with a 'full/teaser' option).

if you use the code from #21, you'll have to name your TPLs like so:
(from "node--nodetype--viewmode")

and not:

other than that, works like a charm. thank you!

Status:Active» Closed (fixed)

You can use by default for teaser in views, without adding anything to template.php:


I used this in D7 to get node--teaser.tpl.php recognised:

function helix_preprocess_node(&$variables, $hook) {
  if($variables['elements']['#view_mode'] == 'teaser'){
    $variables['theme_hook_suggestions'][]= 'node__teaser';