“Begins with” in Twig template

后端 未结 4 1379
半阙折子戏
半阙折子戏 2021-02-05 01:35

I have a twig template where I would like to test if an item begins with a certain value

{% if item.ContentTypeId == \'0x0120\' %}
    

        
4条回答
  •  無奈伤痛
    2021-02-05 01:57

    You can just use the slice filter. Simply do:

    {% if item.ContentTypeId[:6] == '0x0120' %}
    {% endif %}
    

提交回复
热议问题