模板中列表(选择)的匹配值
我找不到一种匹配选择列表的值的方法。
我在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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这在起作用。我发现这个问题,那是因为我已经倒了标签和野外设置中的原始价值,系统价值是资本化的:深色|深光|灯光|大|大,所以它不起作用,因为我没有做在树枝模板中资本化值...因此,我已经在内容的字段设置中倒了标签和原始值。
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.