Tutorial :Add another node display (like teaser, full node) to Drupal [closed]


I would like to have two different displays of a node teaser depending on where it is on the site.

Changing the .tpl of the block alone is not good enough because I need to have a separate imagecache image displayed.

Are there ways to have another display type added? Or change what fields a node display type recieves (ie: the imagecache image displayed)?


As others have pointed out, it's a little unclear what you're doing, but it sounds like your using a node view to create a block and then using the block template to markup the contents of the block. The key contents of such a block will be generated by the node template. The default node template determines its markup based on a $teaser variable set to TRUE or FALSE. The value of $teaser is based on the full node/teaser distinction in views. That's obviously a boolean variable, so there's no third option. So the answer to your specific question is no, you can't do that.

That said, you can accomplish the goal of 3 (or more) different displays by introducing your own variables in template_preprocess_node based on context indicators such as arg() or $view->name, and then using those variables in your own node template (or more likely node type template) to control output markup. You can then apply different imagecache presets by calling the imagecache theme function, something like:

<?php print theme('imagecache', 'thumbnail', $node->field_image[0]['filepath']); ?>  

That's a lot to learn if this is all new to you, hopefully not too overwhelming.


For Drupal 7 users

In Drupal 7 custom node view modes can be easily added by implementing hook_entity_info_alter():

/**  * Implements hook_entity_info_alter().  */  function MYMODULE_entity_info_alter(&$entity_info) {    $entity_info['node']['view modes']['another_teaser'] = array(      'label' => t('Another teaser'),      'custom settings' => TRUE,    );  }   

This will add a new view mode called "Another teaser" to your view mode list which you can configure like any other view mode (like Default or Teaser) too.

See: Drupal 7 custom node view modes (Juha Niemi, Mearra)

Alternatively you can use the module Display Suite but that might be a little overwhelming at first.


It might not be the most elegant solution, but I think you could achieve this by using a combination of CCK and Views.

  • Use CCK to add another field to your content type, one that contains your alternative teaser text.
  • Then, use Views to create the list of nodes where you want the alternative teaser to show up. Include your new teaser field in the view, add some formatting, and you're done.

If you have complex formatting needs, you could try this trick and write a specific .tpl.php file to present the view.


These are called build modes. You have to implement hook_content_build_modes, which will be called by CCK. See CCK for an example.

Next Post »