To show and hide contents in Drupal we can use the javascript library in the core and obtain the same effect that we get by default in the collapsible fields of Drupal forms.
All is needed is to invoke the script collapse.js in the body of the content (node or block) we are creating:
<script type="text/javascript" src="/misc/collapse.js"></script>
and insert the collapsible content in a fieldset to which we will add the class collapsible collapsed:
<fieldset class="collapsible collapsed"> <legend>Title of collapsible content</legend> <div>Hidden text</div> </fieldset>
Select Full HTML for the input format and submit your content. The result will be the following:
I can't seem to get this working under Drupal 6.13. It works fine in preview mode as I'm editing the page, but when I save the page, the collapsed content is gone (collapsed, I guess) but there's no link to expand it.
I've got collapse.js, jquery.js, and drupal.js all included, and I'm using a "raw HTML" mode (no translation of linebreaks or URLs).
I've tried to use this but it doesn't work for anonymous users. But when I'm logged in the field becomes collapsible. How can I make to work with anonymous users?
After enabling OpenID support on my login block, it takes up a a huge portion of the right side bar. Is there a way to use this on a Drupal block. I've seen options to hide a block, but I would love to collapse it to save screen space.
Thanks for sharing this
Thanks for sharing this information. I got a chance to know about this.
Thank you for your tutorial.
Thank you for your tutorial. At the beginning i had few small problems but i`ve done it. Thanks
I can't seem to get this
I can't seem to get this working under Drupal 6.13. It works fine in preview mode as I'm editing the page, but when I save the page, the collapsed content is gone (collapsed, I guess) but there's no link to expand it.
I've got collapse.js, jquery.js, and drupal.js all included, and I'm using a "raw HTML" mode (no translation of linebreaks or URLs).
Maybe a theme problem?
I've tried to use this but
I've tried to use this but it doesn't work for anonymous users. But when I'm logged in the field becomes collapsible. How can I make to work with anonymous users?
collapse login?
After enabling OpenID support on my login block, it takes up a a huge portion of the right side bar. Is there a way to use this on a Drupal block. I've seen options to hide a block, but I would love to collapse it to save screen space.
You need to include the
You need to include the following javascript also
<script type="text/javascript" src="/misc/jquery.js"></script><script type="text/javascript" src="/misc/drupal.js"></script>
very much appreciate
thanks for providing this code
thank you
Thank you for explanations. I had no idea that the collapse.js file is responsible for this action.
Post new comment