我使用hook_theme_suggestions_HOOK_alter()根据内容类型为 page.html.twig 添加主题挂钩建议:
function mytheme_theme_suggestions_page_alter(array &$suggestions, array $variables) {
$node = \Drupal::request()->attributes->get('node');
$suggestions[] = 'page--node--' . $node->getType();
}
Run Code Online (Sandbox Code Playgroud)
现在我的树枝调试模式发现了这一点:
<!-- FILE NAME SUGGESTIONS:
* page--node--case.html.twig (new suggestion based on content type 'case')
* page--node--3.html.twig
* page--node--%.html.twig
* page--node.html.twig
x page.html.twig
-->
Run Code Online (Sandbox Code Playgroud)
但是,当我创建一个名为 的文件时page--node--case.html.twig,它没有被渲染。相反,page.html.twig正在被使用。
有人知道发生了什么事吗?