0

So I have several menu blocks in a region one my drupal 7 site. I need to wrap each of these menu blocks in a <section> tag, but leave all other menu blocks unaffected. My thinking was to preprocess the region, check if the blocks were menu blocks, and as you can see, attempt to simply wrap the output in a section tag. Can someone PLEASE tell me what I'm doing wrong? This problem is killing me.

function mytheme_preprocess_region(&$vars){
    //checks to see if we're in the correct region
    if($vars['region'] == "footer-top"){
            //loops through every block in our region
            foreach($vars['elements'] as $key => $item){
                    $block_type = $item['#block']->module;
                    //if it's a menu block, wrap the output in section tag, this doesnt work
                    if($block_type == "menu_block"){
                            //$vars['elements']['menu_block_4']['#children'] = "<section>" . $item['#children'] . "</section>";
                            $vars['elements'][$key]['#children'] = "<section>" . $item['#children'] . "</section>";
                    }
            }
    }
}
  • Could you write a bit more about the specific problem? What is your code doing instead of what you expected it to do? – NoDataDumpNoContribution May 29 '14 at 21:30
  • Try `foreach($vars['elements'] as &$item){` ($item by ref) – Clive May 29 '14 at 23:36
  • Sorry If I wasn't specific before, my brain was fried... I have one region that currently consists of only menu blocks... I want to wrap each menu block in a
    tag. I only want to do this for this region, so editing block--menu.tpl.php is out, and I'd like to avoid adding a conditional statement to the tpl. (I'd like to keep the .tpl file as markup, not logic) The code checks to see if it's the right region, loops through all of the blocks in the region, and if it's a menu block, tries to wrap the output in a
    tag. I hope this makes more sense. Also, edited the code above.
    – user3408649 May 30 '14 at 03:01

2 Answers2

0

look into block templating. the base block template is in modules/block/block.tpl.php. you can override base template for a specific block.

basically you just need to create a new block template file in your theme folder.

https://drupal.org/node/1089656

Funky Dude
  • 3,867
  • 2
  • 23
  • 33
0
function mytheme_preprocess_block(&$variables) {
  if ($variables['region'] == 'footer-top' && $variables['block']->module == 'menu_block') {
    $variables['content'] = 
            '<section>'. 
                   $variables['elements']['#children'] 
            .'</section>';

  }
}
Ajit S
  • 1,341
  • 1
  • 13
  • 32
Shah Amit
  • 281
  • 1
  • 3