Drupal 7: Modifying menu HTML output?

若如初见. 提交于 2019-12-03 15:34:03

问题


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?


回答1:


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).



来源:https://stackoverflow.com/questions/5189307/drupal-7-modifying-menu-html-output

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!