“Begins with” in Twig template

后端 未结 4 1327
半阙折子戏
半阙折子戏 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:59

    Yes, Twig supports regular expressions in comparisons: http://twig.sensiolabs.org/doc/templates.html#comparisons

    In your case it would be:

    {% if item.ContentTypeId matches '/^0x0120.*/' %}
      ...
    {% else %}
      ...
    {% endif %}
    

提交回复
热议问题