所以我在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>";
}
}
}
}
答案 0 :(得分:0)
查看块模板。基本块模板位于modules / block / block.tpl.php中。您可以覆盖特定块的基本模板。
基本上你只需要在主题文件夹中创建一个新的块模板文件。
答案 1 :(得分:0)
function mytheme_preprocess_block(&$variables) {
if ($variables['region'] == 'footer-top' && $variables['block']->module == 'menu_block') {
$variables['content'] =
'<section>'.
$variables['elements']['#children']
.'</section>';
}
}