简体   繁体   中英

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". Anyone spot what i'm doing wrong?

You are trying to access Wrapper.arrangements in the same way you would a static function. 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:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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