【问题标题】:Drupal 8 block and type classDrupal 8 块和类型类
【发布时间】:2019-11-18 15:51:48
【问题描述】:

我想在树枝布局文件中为块添加自定义类型类:block.html.twig 但我不知道如何输入。 类只是样式需求所需要的,因为我有多种语言的许多块。我不想通过自定义 id 来设置元素的样式。

【问题讨论】:

    标签: drupal drupal-8


    【解决方案1】:

    实际上我找到了一个可行的解决方案,其中一个使用主题挂钩:

    /**
     * Implements hook_preprocess_HOOK() for block.html.twig.
     */
    function MYTHEME_preprocess_block(&$variables) {
    
      // adding custom attribute class for block
      if ($variables['elements']['#base_plugin_id'] == 'block_content') {
        $blockType = strtr($variables['content']['#block_content']->bundle(), '_', '-');
        $variables['attributes']['class'][] = 'block--type-' . $blockType;
      }
    }
    

    这个只是为自定义块类型添加类。但可以满足我的需要。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-11-23
      • 1970-01-01
      • 2016-10-05
      • 2016-06-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-30
      相关资源
      最近更新 更多