如何在一个特定区域中更改drupal 7菜单块的输出?

时间:2014-05-29 21:25:41

标签: php drupal drupal-7 drupal-theming drupal-regions

所以我在drupal 7网站的某个区域有几个菜单块。我需要将每个菜单块包装在<section>标记中,但不要影响所有其他菜单块。我的想法是预处理区域,检查块是否是菜单块,如您所见,尝试简单地将输出包装在section标签中。有人可以告诉我我做错了什么吗?这个问题让我很难过。

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>";
                    }
            }
    }
}

2 个答案:

答案 0 :(得分:0)

查看块模板。基本块模板位于modules / block / block.tpl.php中。您可以覆盖特定块的基本模板。

基本上你只需要在主题文件夹中创建一个新的块模板文件。

https://drupal.org/node/1089656

答案 1 :(得分:0)

function mytheme_preprocess_block(&$variables) {
  if ($variables['region'] == 'footer-top' && $variables['block']->module == 'menu_block') {
    $variables['content'] = 
            '<section>'. 
                   $variables['elements']['#children'] 
            .'</section>';

  }
}