【问题标题】:Drupal block twig fileDrupal 块树枝文件
【发布时间】:2016-11-08 05:58:03
【问题描述】:

我的内容类型为“新闻”。对于这种内容类型,我需要显示最新的 5 篇文章。所以我使用视图创建了块。它很好地显示了文章,但我需要使用树枝文件添加我自己的 css。我尝试了以下选项,但没有一个能正常工作。

   block--newsblock.html.twig
block--newsblock-block.html.twig
views--view-newsblock-block.html.twig

但是当我通过以下方式申请时,字段模板正在调用。

views-view-fields--newsblock--block.html.twig

我想要的是块中的第一个元素,我需要为其余部分显示一些预告文本,我只需要显示标题。我该怎么做?

【问题讨论】:

    标签: css symfony drupal drupal-8


    【解决方案1】:

    激活 twig 调试并查看您的控制台 它会告诉你建议使用的文件名

    或者将此钩子添加到 your_theme_name.theme 以提出您自己的建议

    /**
     * Implements hook_theme_suggestions_HOOK_alter() for block templates.
     */
    function your_theme_theme_suggestions_block_alter(array &$suggestions, array $variables) {
      $block_id = $variables['elements']['#id'];
    
      /* Uncomment the line below to see variables you can use to target a block */
      // print $block_id . '<br/>';
    
      /* Add classes based on the block id. */
      switch ($block_id) {
    
        case 'your_block_id':
          $suggestions[] = 'block__newsblock';
          break;
      }
    }
    

    然后是块--newsblock.html.twig

    【讨论】:

    • 如果我们能以某种方式为 Drupal 8 启用 twig 主题调试,那就太棒了。
    猜你喜欢
    • 2016-10-05
    • 2019-11-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-10
    • 1970-01-01
    相关资源
    最近更新 更多