Drupal 8/9 中的 css 段落背景图像参考

问题描述 投票:0回答:0

我正在使用段落模块。在这一段中,我有一个图像、文本和一个背景图像。我想使用背景图像作为段落的背景。我拥有所有选择器,但不知道如何从我的 css 预处理中访问变量 bg。

我的预处理:

$media = $paragraph->field_img->entity->field_media_image->entity;
$text = $paragraph->field_img_text->value;
$bg = $paragraph->field_bg_img->entity->field_media_image->entity;

$variables['image'] = [
  '#theme' => 'image_style',
  '#style_name' => 'max_650x650',
  '#uri' => $media->getFileUri(),
];

$variables['text'] = [
  '#type' => 'processed_text',
  '#text' => $text,
  '#format' => $paragraph->field_img_text->format,
];

$variables['bg'] = [
  '#theme' => 'image_style',
  '#style_name' => 'hero_image',
  '#uri' => $bg->getFileUri(),
];

scss 选择器:

.paragraph--type--text-image- {
    background-color: gray;
}

树枝文件:

    <div{{ container_attributes }} >
      {% block content %}
        {% if image %}
          <div class="image-container">
            {{ image }}
          </div>
        {% endif %}
        <div class="text-container">
      {{ text }}
      </div>
      {% endblock %}
    </div>
  </section>
{% endblock paragraph %}
php drupal twig drupal-8
© www.soinside.com 2019 - 2024. All rights reserved.