简体   繁体   English

检查清单包含Twig模板中的值

[英]Check list contains value in Twig template

I have this block of code: 我有这段代码:

<div>
    <dt class="question">Language</dt>
    <dd class="answer">
    {% if Wrapper.arrangements['signLanguage'] is defined %}
        Sign Language              
    {% else %}
        Not required
    {% endif %}
    </dd>
</div>

and then: 接着:

@Value
@Builder
public class Wrapper {

    private List<String> arrangements;

}

Which always prints 'Not required' even when my Java Wrapper.arrangements object contains "signLanguage". 即使我的Java Wrapper.arrangements对象包含“ signLanguage”,该选项也始终显示“不需要”。 Anyone spot what i'm doing wrong? 有人发现我在做什么错吗?

You are trying to access Wrapper.arrangements in the same way you would a static function. 您试图以与静态函数相同的方式访问Wrapper.arrangements。 It is not static and is private so you will need to add the wrapper to your model presumably named "wrapper" and have a method named getArrangement that returns your arrangements list then in your template you will have the following: 它不是静态的,而是私有的,因此您需要将包装器添加到模型中(大概名为“ wrapper”),并具有一个名为getArrangement的方法,该方法返回您的布置列表,然后在模板中将具有以下内容:

{% if wrapper.getArrangements.contains('signLanguage') is defined %}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM