模板中列表(选择)的匹配值

发布于 2025-02-05 21:17:02 字数 907 浏览 3 评论 0原文

我找不到一种匹配选择列表的值的方法。

我在Drupal段落中添加了list字段类型,并带有以下值:

  • Light
  • Dark
  • Big。

我想使用这些值能够在一个段落内应用不同的样式,这是通过在编辑表单中选择其中一个值来应用的。

 {% set paragraph_jumbotron = content.field_paragraph_jumbotron %}
  {% block content %}
    {% for item in paragraph_jumbotron['#items'] %}
      {% if item.entity.field_selector.value == 'big' %}
        <div class="p-5 mb-4 bg-light rounded-3">
          ...
          </div>
        </div>
      {% elseif item.entity.field_selector.value == 'dark' %}
        <div class="h-100 p-5 text-white bg-dark rounded-3">
          ...
        </div>

      {% elseif item.entity.field_selector.value == 'light' %}
        <div class="h-100 p-5 text-white bg-dark rounded-3">
          ...
        </div>
      {% endif %}
    {% endfor %}
  {% endblock %}

I cant find a way to match the value of a select list.

I added a list type of field in a Drupal paragraph, with following values:

  • light
  • dark
  • big.

I want to use those values to be able to apply different styles within one paragraph, this by selecting one of these values in the edit form.

 {% set paragraph_jumbotron = content.field_paragraph_jumbotron %}
  {% block content %}
    {% for item in paragraph_jumbotron['#items'] %}
      {% if item.entity.field_selector.value == 'big' %}
        <div class="p-5 mb-4 bg-light rounded-3">
          ...
          </div>
        </div>
      {% elseif item.entity.field_selector.value == 'dark' %}
        <div class="h-100 p-5 text-white bg-dark rounded-3">
          ...
        </div>

      {% elseif item.entity.field_selector.value == 'light' %}
        <div class="h-100 p-5 text-white bg-dark rounded-3">
          ...
        </div>
      {% endif %}
    {% endfor %}
  {% endblock %}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

丘比特射中我 2025-02-12 21:17:02

这在起作用。我发现这个问题,那是因为我已经倒了标签和野外设置中的原始价值,系统价值是资本化的:深色|深光|灯光|大|大,所以它不起作用,因为我没有做在树枝模板中资本化值...因此,我已经在内容的字段设置中倒了标签和原始值。

This is working. I find out the problem, it was because I've inverted the label and the raw value in he field settings, the system value was capitalized: Dark|dark Light|light Big|big So it did'nt work because i did'nt capitalize the value in the twig template... Thus i've inverted the label and the raw value in the field settings of the content.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文