Drupal 7:修改菜单HTML输出? [英] Drupal 7: Modifying menu HTML output?

查看:401
本文介绍了Drupal 7:修改菜单HTML输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



基本上,而不是<只包含简单的a> s与文本,我想包括一些额外的HTML在< a>。



我知道可以修改由Drupal中的菜单创建的HTML。我可以在page.tpl.php中看到以下调用:

 <?php print theme ('links__system_main_menu',array(
'links'=> $ main_menu,
'attributes'=>数组(
'id'=>'主菜单',
'class'=> array('links','clearfix'),
),
'heading'=>数组(
'text'=> t '),
'level'=>'h2',
'class'=> array('element-invisible'),
),
)); ?>

这显然调用了主题功能,它创建了输出。修改输出的一种方法是修改theme.inc中的theme_links函数,对吧?



http://api.drupal.org/api/drupal/includes--theme.inc/function/theme_links



我也知道你可以在template.php中挂钩来覆盖创建HTML的函数。我不知道如何创建实际的覆盖功能。有人可以指出我正确的方向吗?

解决方案

你会做的是实现一个钩子来修改输出,而不直接修改theme.inc文件。 / p>

例如,本页面上接受的答案: Drupal覆盖自定义菜单模板






作为一般规则,当您要修改输出的一些东西,要么是实现钩子 (在模块中或活动主题的template.php中)或使用具有预定义文件名的模板当这种情况存在时(没有模板已经存在,你也可以修改模板建议列表s 使用模块或主题)。


I am trying to modify the HTML output in a Drupal 7 theme that I am creating.

Basically, instead of the < li >s containing just plain < a >s with text, I want to include some additional HTML inside the < a >.

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'),
      ),
    )); ?>

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

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?

解决方案

What you would do is implement a hook to modify the output, not modify the "theme.inc" file directly.

For example, the accepted answer on this page: Drupal Override Custom Menu Template


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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆