Php D8车身等级
我花了很长时间试图在D8中学习我的身体元素。我正在使用一个自定义主题,到目前为止我的代码如下所示: themename.themePhp D8车身等级,php,drupal,twig,drupal-8,theming,Php,Drupal,Twig,Drupal 8,Theming,我花了很长时间试图在D8中学习我的身体元素。我正在使用一个自定义主题,到目前为止我的代码如下所示: themename.theme use Drupal\Component\Utility\Html; /** * Preprocess variables for html templates. */ function HOOK_preprocess_html(&$variables) { $path_class = !$variables['root_path'] ? 'pat
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) }}>
{%
设置正文\u类=[
不是根路径?“路径frontpage”:“路径-”~root_路径| clean_类,
]
%}
我在body元素上得到了类,但是NID是空的,读“page node”,我需要它读“page node NID”。你必须用主题名替换HOOK
myteme\u preprocess\u html
,否则Drupal不会调用HOOK