在Drupal 8中将体类添加到节点

时间:2015-12-07 23:15:51

标签: twig drupal-8

我正在尝试使用Drupal 8.我已经创建了一个本地沙盒网站,并使用Twig创建了一个自定义主题和自定义首页(page - front.html.twig)。我想添加一些仅定位于首页的自定义CSS,我习惯于定位body.page-node-x(Drupal 7)。在Drupal 8中,我在向此自定义页面添加正文类时遇到问题。我看到的唯一正文类是工具栏 - 托盘 - 打开工具栏 - 固定工具栏 - 水平。

2 个答案:

答案 0 :(得分:2)

添加body标签的frontpage,登录和节点类型类。修改 html.html.twig 并添加:

{%
  set body_classes = [
    logged_in ? 'logged-in',
    not root_path ? 'frontpage' : 'path-' ~ root_path|clean_class,
    node_type ? 'node--type-' ~ node_type|clean_class,
  ]
%}

<body{{ attributes.addClass(body_classes) }}>

答案 1 :(得分:0)

您需要在&#34;中添加这些代码。 html.html.twig&#34;您可以在核心主题中找到的模板&#34;优雅&#34;在drupal 8中

<?php
{%
  set body_classes = [
    logged_in ? 'user-logged-in',
    not root_path ? 'path-frontpage' : 'path-' ~ root_path|clean_class,
    node_type ? 'page-node-type-' ~ node_type|clean_class,

  ]
%}
?>