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):

    <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 class=”mysecondfield”>
    <?php print $node->field_mysecondfield[0][‘view’] ?>

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

3 responses to “collapsible content using contemplate”

  1. Thanx for the snippet. This works great in a particular node for a Content Type in Drupal 6.

    If I want to apply the collapse/expand effect on a ‘view’ generated page (like a news page), how do I do that?


    • Hi Sridhar, you can use also jQuery toggle instead collapsible fieldset, it’s a cleaner approach. To customize your views as you wish, just edit your view and on Default or on your specific Display (Block, page, …) select Theme Information. You’ll see a list with all potential templates for your view. If you click on Display output or Style output, you’ll get the code you have to use for customization. You’ve just to copy and past that code into a template with one of the name suggested on the previous screen, save into your active theme directory (es. sites/ and after that click on “Rescan template files” on Theme information.

      After that, you can change your template to wrap elements with fieldset or toggled divs as you like.

      Good coding!

%d bloggers like this: