Drupal 7:修改菜单 HTML 输出? [英] Drupal 7: Modifying menu HTML output?
问题描述
我正在尝试修改我正在创建的 Drupal 7 主题中的 HTML 输出.
I am trying to modify the HTML output in a Drupal 7 theme that I am creating.
基本上,而不是 <li >s 只包含简单的 <带有文本的 >s,我想在 < 中包含一些额外的 HTML一个>.
Basically, instead of the < li >s containing just plain < a >s with text, I want to include some additional HTML inside the < a >.
我知道可以修改由 Drupal 中的菜单创建的 HTML.我可以在 page.tpl.php 中看到以下调用:
I know that it's possible to modify the HTML created by the menus in Drupal. I can see the following call in page.tpl.php:
<?php print theme('links__system_main_menu', array(
'links' => $main_menu,
'attributes' => array(
'id' => 'main-menu',
'class' => array('links', 'clearfix'),
),
'heading' => array(
'text' => t(''),
'level' => 'h2',
'class' => array('element-invisible'),
),
)); ?>
这显然调用了主题函数,它创建了输出.修改输出的一种方法是修改 theme.inc 中的 theme_links 函数,对吗?
which apparently calls the theme function, which creates the output. One way to modify the output would be to modify the theme_links function in theme.inc, right?
http://api.drupal.org/api/drupal/includes--theme.inc/function/theme_links
我也知道您可以在 template.php 中放置一个钩子来覆盖创建 HTML 的函数.我不知道如何创建实际的覆盖功能.有人可以指出我正确的方向吗?
I also know that you can put a hook in template.php to override the function which creates the HTML. I can't figure out how to create the actual override function. Can somebody point me in the right direction, please?
推荐答案
你要做的是实现一个钩子来修改输出,而不是直接修改theme.inc"文件.
What you would do is implement a hook to modify the output, not modify the "theme.inc" file directly.
例如,此页面上接受的答案:Drupal 覆盖自定义菜单模板
For example, the accepted answer on this page: Drupal Override Custom Menu Template
作为一般规则,当您想修改某些内容的输出时,实现一个钩子(在模块或活动主题的template.php中)或使用模板带有预定义的文件名 当这种情况存在时(当没有模板时,你也可以使用模块或主题修改模板建议列表.
And as a general rule, when you want to modify the output of something, either implement a hook (in a module or in the template.php of the active theme) or use a template with a predefined file name when such a case exists (when no template already exists, you can also modify the list of template suggestions using a module or the theme).
这篇关于Drupal 7:修改菜单 HTML 输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!