2

I am trying to change the <h2> tags that block.tpl.php uses to wrap <?php print $block->subject ?> to <h3> tags so that I can target them with jQuery UI Accordion. I've got the following code:

<?php
    function MYTHEME_block_view_alter(&$data, $block) {
        if($block->module == 'block' && $block->region == 'sidebar') {
            $data['subject']['#tag'] = 'h3';
        }
    }
?>

This doesn't work...I assume I'm screwing up the reference to the render element. Does $data['subject'] contain an array where the HTML tag is stored? What is the correct way to target it?

Alternatively, should I look for a way to re-write block markup so that, in the sidebar region, it renders only the <h3> and <div> required by jQuery UI Accordion? Unless there's a fantastic module for turning blocks into Accordion-ready HTML already out there, I'd rather not install another module.

Many thanks for any help!

2 Answers 2

2

You can override the block template for a particular block and can modify the html for block subject.

You can check theme suggestions for more reference.

1
  • That's what I ended up doing, but I had hoped I wouldn't need to override block.tpl.php just for blocks in that region. I got rid of the wrapper <div> around each block so that jQuery UI Accordion would get the HTML structure it expects, and I moved the block attributes and classes to the <h3> that used to replace the default <h2> hardcoded in block.tpl.php. Commented Apr 21, 2013 at 14:52
0

You can rewrite the block output using HOOK_BLOCK_VIEW_ALTER

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.