【发布时间】: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