Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Thought I'd share this:
Here's how I made the Block Div's hidable using javascript (and scriptaculous.js). Put it somewhere in the page, or in a separate file, that gets included in the page..
<script language="javascript" type="text/javascript">
// make blocks collapse by clicking on title.
blocks=document.getElementsByTagName("div");
blocks=$A(blocks);
blocks.each (
function(block){
if (block.className=='block') {
title=block.childNodes[1];
title.onclick = function () {
content=this.parentNode.childNodes[3];
content.style.display!='none' ? content.style.display='none' : content.style.display='block';
}
}
}
);
</script>
(To add: some cookie stuff to let the browser remember which blocks you've got hiding/showing.)
<script language="javascript" type="text/javascript">
// Assuming jQuery.noConflict is already called.
if (Drupal.jsEnabled) {
$(document).observe('dom:loaded', function() {
$$('div.block h2').invoke('observe', 'click', function() {
$(this).up().down('div.content').invoke('toggle');
});
});
}
</script>
<script language="javascript" type="text/javascript">
if (Drupal.jsEnabled) {
(function($) {
$('div.block h2').click(function() {
$(this).parent().find('div.content').slideToggle();
});
})(jQuery);
}
</script>
More info: See 'Collapsiblock' under jstools module for a full-blown and configurable version of this task. I think it's cookied by now.
Comments
Drupal 6: Collapsiblock
Drupal 6 users can use Javascript Tools Collapsiblock to achieve the same.
separate project
Actually Collapsiblock is a separate project.
https://interface-network.com - Interface Network is an action and research technology governance agency.
If you're already using ctools in drupal 7
This solution worked for me in drupal 7 with ctools (I can't imagine a drupal 7 site not using ctools).
If you're trying to make all sidebar blocks collapsible, create a new file in your theme's templates folder called "block--sidebar-first.tpl.php". Or if you're trying to make only a specific block collapsible, for example a views block, create a new file named "block--views--my-view-name-my-display-name.tpl.php".
In you're new tpl file, just add the following PHP snippet:
and clear cache. ctools will do the rest :-)
danielgurtner.com
Hi dangswiss
Hi dangswiss
Thanks for your suggestion/solution - however, I cannot make it work. I have a view named 'Pending users', which I insert into Panels using display 'Block'. So, I create af .php file named:
block--views—pending-users-block.tpl.php
with the snipped that you provided. I clear the cache, but no change, nothing to click on, not collapsible.
What am I doing wrong here? Thanks in advance!
Best,
Thomas