Render different teaser & full node code within single template

When using a custom content template (node.tpl.php) you can use the $teaser and $page values to differentiate what is shown in the full node and the teaser view.

Below are some examples:

<?php
  if ($teaser) {
    // node is being displayed as a teaser
  } else {
    //all other cases
  }
?>
<?php if ($teaser): ?>
    <!-- teaser template HTML here -->
  <?php else: ?>
    <!-- regular node view template HTML here -->
<?php endif; ?>
<?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
  } 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
  }
?>
Justin Chevallier

Justin Chevallier

Avid Drupal site builder & user for +9 years.

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.