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.
Comments
Comment #1
Rob_Feature CreditAttribution: Rob_Feature commentedquick correction in paragraph one (sorry for the bad proofread):
Comment #2
mfer CreditAttribution: mfer commentedsubscribe
Comment #3
joachim CreditAttribution: joachim commentedI 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:
node
node-TYPE
node-TEASER
or:
node
node-TEASER
node-TYPE
Comment #4
Rob_Feature CreditAttribution: Rob_Feature commentedI 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.
Comment #5
mfer CreditAttribution: mfer commentedMy 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?
Comment #6
mfer CreditAttribution: mfer commentedComment #7
Rob_Feature CreditAttribution: Rob_Feature commentedmfer: 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.
Comment #8
mfer CreditAttribution: mfer commentedComment #9
akahn CreditAttribution: akahn commentedmfer,
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.
-Alex
Comment #10
mfer CreditAttribution: mfer commentedComment #11
kika CreditAttribution: kika commentedHow does it map with #372743: Body and teaser as fields ?
Comment #12
mfer CreditAttribution: mfer commentedThanks @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?
Comment #13
bjaspan CreditAttribution: bjaspan commentedI 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.
Comment #14
bradwade CreditAttribution: bradwade commented+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.
Comment #15
JohnAlbinI hate teasers. Mostly because they're difficult to theme.
I assume we would also have template suggestions like node-teaser-NODETYPE.tpl.php?
Comment #16
mason@thecodingdesigner.com CreditAttribution: mason@thecodingdesigner.com commented+1, and it's about time! This will make logical sense to novice themers.
Comment #17
mfer CreditAttribution: mfer commentedPostponing until #372743: Body and teaser as fields goes in.
Comment #18
yched CreditAttribution: yched commentedYou might be interested in #409750: Overhaul and extend node build modes too...
Comment #19
mstrelan CreditAttribution: mstrelan commentedHere 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.
This is not just specific to content types, you could do this for the generic node.tpl.php as well.
Comment #20
JohnAlbinMichael, here's a much better way to do it in D6:
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.
So
$vars['theme_hook_suggestions'][] == 'node__teaser';
would load a node--teaser.tpl.php file.Comment #21
Anonymous (not verified) CreditAttribution: Anonymous commented@#21 in D7 I do this:
Comment #22
pjcard CreditAttribution: pjcard commented@morningtime Thank you, exactly what I needed. Very impressed at how easy it was to implement!
Comment #23
okj579 CreditAttribution: okj579 commentedAnother +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.
Comment #24
mesr01 CreditAttribution: mesr01 commentedCheck out the Display Suite Module for template suggestions specific to view modes.
Comment #25
Rob_Feature CreditAttribution: Rob_Feature commentedJust 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).
Comment #26
luco CreditAttribution: luco commentedif you use the code from #21, you'll have to name your TPLs like so:
node--page--teaser.tpl.php
(from "node--nodetype--viewmode")
and not:
node--teaser.tpl.php
other than that, works like a charm. thank you!
Comment #27
CPJS CreditAttribution: CPJS commentedYou can use by default for teaser in views, without adding anything to template.php:
node--view--viewsname.tpl.php
Comment #28
StephenRobinson CreditAttribution: StephenRobinson commentedI used this in D7 to get node--teaser.tpl.php recognised:
Comment #29
fweiss CreditAttribution: fweiss commentedFunctions killed my template.php file, any thoughts to why?