0

在 Drupal 中,我在节点模板中呈现分类项目列表,使用

print render($content['field_my_taxonomy']);

它显示如下列表:

<ul class="links">
  <li class="taxonomy-term-reference-0">
       <a property="rdfs:label skos:prefLabel" typeof="skos:Concept" href="somewhere">
         Tomaten
       </a>
   </li>
   (...)

到现在为止还挺好。现在,我想将我自己的一些类应用于li标签和ul标签。

我设法通过theme_preprocess_node为每个li标签添加了一个类:

$vars['content']['field_my_taxonomy'][$i]['#options']['attributes']['class'] = "my-li-class";

(其中 $i 包含 li-item 的索引)。

但是,我找不到将类添加到UL的类似程序

我发现了涉及为特定字段创建模板文件,或涉及完全覆盖分类项目的主题功能的灵魂。我不喜欢这些解决方案,因为这涉及为我的主题添加相当多的“臃肿”。我只想向数组中添加一个新项目,让 Drupal 负责渲染。当然,必须可以将 ['attributes']['class']='my-ul-class添加到某处的数组中?

4

1 回答 1

0

您可以覆盖theme_item_list($variables)主题函数实现hook_preprocess_item_list($variables)我认为的 hook_preprocess_HOOK 函数。第一个将在主题本身中进行更改,第二个将在进入正常主题功能之前进行更改。

链接:

http://api.drupal.org/api/drupal/includes!theme.inc/function/theme_item_list/7

http://api.drupal.org/api/drupal/modules!system!theme.api.php/function/hook_preprocess_HOOK/7

于 2013-02-15T09:38:56.147 回答