collapsible content using contemplate

How to make a collapsible content body with Contemplate and the Drupal core “collapsible” function?

  1. Make sure you’ve Contemplate enabled (through admin/build/modules)
  2. Go to admin/content/templates and choose the type you want to display collapsible content within.
  3. Enable body contemplate checking “Affect body output” and write (change field names):

    <?php
    drupal_add_js(’misc/collapse.js’);
    drupal_add_js(’misc/drupal.js’);
    ?>
    <fieldset class=”collapsible collapsed”>
    <legend><?php print t(”My Translatable First Field Label”)?></legend>
    <div class=”fieldset-wrapper”>
    <h2><?php print t(”My Translatable First Field Header”)?></h2>
    <?php print $node->field_myfirstfield[0]['view'] ?>
    </div>
    </fieldset>

    <div class=”mysecondfield”>
    <?php print $node->field_mysecondfield[0]['view'] ?>
    </div>

Update: If you want a collapsible box expanded by default, use class=”collapsible” without “collapsed” class.

See also:
Add collapsible content in Drupal @ Random Snippets

1 Response to “collapsible content using contemplate”


  1. 1 Shorav January 7, 2008 at 9:41 pm

    Thanks for the code snippet.

Leave a Reply