【问题标题】:D8 Body ClassesD8 身体课程
【发布时间】:2016-09-07 21:04:09
【问题描述】:

我在尝试在 D8 中获取关于我的 body 元素的课程时遇到了麻烦。我正在使用自定义主题,目前的代码如下所示:

themename.theme

use Drupal\Component\Utility\Html;

/**
 * Preprocess variables for html templates.
 */
function HOOK_preprocess_html(&$variables) {
  $path_class = !$variables['root_path'] ? 'path-frontpage' : 'path-' . Html::getClass($variables['root_path']);
  if (isset($path_class)) {
    $variables['attributes']['class'][] = $path_class;
  }
}

html.html.twig

    {%
        set body_classes = [
          not root_path ? 'path-frontpage' : 'path-' ~ root_path|clean_class,
        ]
      %}
<body{{ attributes.addClass(body_classes) }}>

我在我的 body 元素上获得了类,但 NID 是空的,正在读取,'page-node' 我需要它来读取,'page-node-NID'。

【问题讨论】:

    标签: php drupal twig drupal-8 theming


    【解决方案1】:

    您必须将 HOOK 替换为您的主题名称 mytheme_preprocess_html 否则 Drupal 不会调用该钩子。

    【讨论】:

      猜你喜欢
      • 2013-07-26
      • 1970-01-01
      • 1970-01-01
      • 2021-05-17
      • 1970-01-01
      • 2019-11-15
      • 2022-01-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多