我使用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();
}现在,我的twig调试模式获得了以下内容:
<!-- 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
-->但是,当我创建一个名为page--node--case.html.twig的文件时,它不会被呈现。相反,page.html.twig正在被使用。
有人知道怎么回事吗?
发布于 2015-08-18 14:22:26
我发现了出了什么问题。
显然,在定义新建议时,Drupal需要下划线而不是破折号。然后,Drupal将这些下划线转换为破折号,以便实际文件名仍然是页-节点--Case.html.twig。
所以:$suggestions [] = 'page--node--'.$node->gettype();
应该是:$suggestions [] = 'page__node__'.$node->gettype();
https://stackoverflow.com/questions/32071938
复制相似问题