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

Advertisements

3 thoughts on “collapsible content using contemplate

  1. sri20198

    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?

    Regards,
    Sridhar

    Reply
    1. chirale Post author

      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/example.com/themes/mytheme) 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!

      Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s