【问题标题】:Difference between $attributes and $classes in Drupal theming?Drupal 主题中 $attributes 和 $classes 的区别?
【发布时间】:2026-01-29 14:05:02
【问题描述】:

在面板 TPL 文件中,我有以下内容,但是这会将类打印两次。

<div class="<?php print $classes; ?>" <?php print $id; ?> <?php print $attributes; ?>>

这有区别吗:

class="<?php print $classes; ?>"

还有这个?:

<?php print $attributes; ?>

【问题讨论】:

    标签: drupal-theming


    【解决方案1】:

    如您所见,class="&lt;?php print $classes; ?&gt;" 仅打印元素中 class 属性的类,而 &lt;?php print $attributes; ?&gt; 打印该元素的所有属性:类、样式、值、样式、自定义属性,如“标签" 或 "可见性" 等...

    因此,您可以打印具有这两个功能的类。如果您只想打印类,请使用print $classes,如果您想打印所有项目属性(包括类),请使用print $attributes

    【讨论】: