【问题标题】:Drupal 8 page.html.twig per content type每个内容类型的 Drupal 8 page.html.twig
【发布时间】:2014-12-06 11:20:42
【问题描述】:

有没有办法为自定义内容类型制作自定义 page.html.twig page--node--content-type.html.twig?

目前我们得到 页面--节点--%.html.twig...

【问题讨论】:

    标签: drupal drupal-8


    【解决方案1】:

    将以下代码放入您的 theme_name.theme 文件

    function theme_name_theme_suggestions_page_alter(array &$suggestions, array $variables) {
      if ($node = \Drupal::routeMatch()->getParameter('node')) {
        $content_type = $node->bundle();
        $suggestions[] = 'page__'.$content_type;
      }
    }
    

    然后对于“自定义”内容类型,您可以创建“页面--custom.html.twig”文件。

    【讨论】:

    • 您的“页面--custom.html.twig”的网址是什么?
    猜你喜欢
    • 2020-11-06
    • 2017-11-13
    • 1970-01-01
    • 1970-01-01
    • 2016-12-30
    • 1970-01-01
    • 2013-09-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多