我正在为基于 bootstrap 的 Drupal 7 设计一个主题。我不使用特殊的基本主题,我手动完成所有操作。
您需要确保菜单中指向主页的链接看起来像一个字形的房子:
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<a href="#"><span class="glyphicon glyphicon-home"></span></a>
我正在尝试像这样实现它:
function imit_menu_link__main_menu ($variables) {
$element = $variables['element'];
$sub_menu = '';
if ($element['#below']) {
$sub_menu = drupal_render($element['#below']);
}
if ($element['#href'] == '<front>') {
$element['#title'] = '<span class="glyphicon glyphicon-home"></span>';
}
$output = l($element['#title'], $element['#href']);
return '<li' . drupal_attributes($element['#attributes']) . '>' . $output . $sub_menu . "</li>\n";
}
但最后,标签span显示为纯文本。如何强制将其呈现为 HTML 元素?
必须允许转换成html
有关可以通过#localized_options 传递的更多选项,请参阅此处- 它作为 $options 数组到达那里。顺便说一句,有一个模块https://www.drupal.org/project/menu_html用于此类任务的简单解决方案。