Theming the node teaser
You can give a teaser its own unique look by using the following condition on any node.tpl.php file:
<?php
if ($teaser) {
//if node is being displayed as a teaser
//Anything here will show up when the teaser of the post is viewed in your taxonomies or front page
} else {
//all other cases
//Anything here will show up when viewing your post at any other time, e.g. previews
?> Or, if you want to use HTML within the conditions, for example to make two completely different layout within the template:
<?php if ($teaser): ?>
<!-- teaser template HTML here -->
<?php else: ?>
<!-- regular node view template HTML here -->
<?php endif; ?>Note that the $page variable indicates whether a node is standing alone or not, which isn't necessarily the same as whether it's being shown as a teaser: $page is set to true in the node edit preview.

$teaser
Instead of using $page, you should be able to use $teaser.
There are legitimate situations where page == 0 and it's not supposed to be a teaser. For example, when you preview a node.
Instead, test whether $teaser == 0 or $teaser == 1. (i.e. your test for $page == 0 should be $teaser == 1) and vice versa. This works (at least) in 5.0-rc-1, and it looks like it should be the same in 4.7.
This one took me hours to figure out....
Fun with language constructs
This was massively helpful to me! Exactly what I was looking for.
So there's a few variations one could use for efficiency's sake ... rather than two IF statements you could make use of ELSE, like so:
<?phpif ($teaser) { //if node is being displayed as a teaser
//Anything here will show up when the teaser of the post is viewed in your taxonomies or front page
} else { //all other cases
//Anything here will show up when viewing your post at any other time, e.g. previews
}
?>
Or alternatively, if you're really eager to plan for those non-page events, you could add a case and include a default:
<?phpif ($teaser) { //if node is being displayed as a teaser
//Anything here will show up when the teaser of the post is viewed in your taxonomies or front page
} elseif ($page) { //if node is being displayed as a full node
//Anything here will show up when viewing only your post
} else { //all other cases
//Anything here will show up when viewing your post at any other time
}
?>
BTW, I'm kind of assuming $teaser and $page will only ever be 1 or 0 here.
$teaser holds the teaser
$teaser holds the teaser text loaded from the database.
So you can test that it exists with if($teaser) but testing if($teaser == 1) doesn't work. ==0 is, I'm guessing, the same as saying == FALSE. This will work.... usually. If a site has been set up to show no body text at all in node teasers, the variable would be empty and the test would give a false positive.
$teaser does not hold the teaser text!!
>$teaser holds the teaser text loaded from the database.
http://api.drupal.org/api/function/phptemplate_node/5 implies that it holds the boolean that indicates whether the node is being viewed in teaser format or not. I've confirmed this by inspecting variables within node.tpl.php. The parent page to this one is actually wrong in its description of $teaser.
The teaser text is in $content, $node->teaser, $node->content['body']['#value'] and I think $node->content['#children'], when the node is being viewed as a teaser ($teaser == TRUE).
When the node is being viewed as a full page, the body is available in $body, $content, $node->body, $node->content['body']['#value'] $node->content['#children'].
Notes:
1. This is slightly inconsistent, in that $body exists only in full page view and is the content, whereas $teaser exists in both instances and is an integer or a boolean (can be treated as a boolean in any case)
2. In teaser view, $node->body gets unset, and in full page view $node->teaser gets unset (this happens in node_view and is maybe no longer necessary http://drupal.org/node/83758).
[edited following tests to confirm what $teaser is and what other variables are exposed to the node template]
gpk
----
www.alexoria.co.uk
Right you are -- I was
Right you are -- I was thinking of $node->teaser!
Duncf is makes a huge point
Duncf is makes a huge point about using $teaser instead of $page to toggle display of a node.
Another situation where $page ==0 and it's not supposed to be a teaser, is in the views.module when you try to create a 'Full nodes' view type.
This also took me hours to figure out...
-zach
--
harkey design