Drupal7-如何为每个页面添加唯一的类名?

Drupal7-如何为每个页面添加唯一的类名?,drupal,drupal-7,Drupal,Drupal 7,我进入Drupal的第二天很困惑。。。我需要在body标签中添加一个唯一的类名来标识每个页面,因为在整个站点的每个页面上都有许多独特的样式(重复元素) 我在网上找到了一些代码片段,但它们不起作用。例如,我已将其添加到template.php文件中,但它不起作用: function testtheme_preprocess_html(&$vars) { // my theme is called "testtheme" $path = drupal_get_path_alias($_G

我进入Drupal的第二天很困惑。。。我需要在body标签中添加一个唯一的类名来标识每个页面,因为在整个站点的每个页面上都有许多独特的样式(重复元素)

我在网上找到了一些代码片段,但它们不起作用。例如,我已将其添加到
template.php
文件中,但它不起作用:

function testtheme_preprocess_html(&$vars) { // my theme is called "testtheme"
  $path = drupal_get_path_alias($_GET['q']);
  $aliases = explode('/', $path);

  foreach($aliases as $alias) {
    $vars['classes_array'][] = drupal_clean_css_identifier($alias);
  } 
}

假设向body标记添加一个类,但是没有显示任何内容。我遗漏了什么,或者有人能提供另一种解决方案吗?

如果我没有正确理解您的意思,很抱歉,但是您可以在html.tpl.php文件的body标记中添加代码,使其看起来像这样:

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

降雨的答案是正确的,但是: drupal中的body元素page NAMEPAGE中已经存在唯一的逐页类,您可以修改模块:

1) 节点类模块中的注释功能节点类预处理节点

2) 插入

在page.tpl.php中 以前


在template.php中添加函数后是否清除了缓存?可能是因为代码“破坏”了某些内容。也许最好将它删除到一开始的样子,然后将我放在那里的代码放到html.tpl.php中?
$node_classes = node_class($node);
if (!empty($node_classes)) $node_classes .= ' ';
$content_column_class = str_replace(' class="','', $content_column_class);
$content_column_class = ' class="'. $node_classes . $content_column_class;
<section<?php print $content_column_class; ?> id="content_col">