Twig: in_array or similar possible within if statement?

后端 未结 6 692
终归单人心
终归单人心 2020-12-12 11:57

I am using Twig as templating engine and I am really loving it. However, now I have run in a situation which definitely mustbe accomplishable in a simpler way than I have fo

6条回答
  •  温柔的废话
    2020-12-12 12:23

    Though The above answers are right, I found something more user-friendly approach while using ternary operator.

    {{ attachment in item['Attachments'][0] ? 'y' : 'n' }}
    

    If someone need to work through foreach then,

    {% for attachment in attachments %}
        {{ attachment in item['Attachments'][0] ? 'y' : 'n' }}
    {% endfor %}
    

提交回复
热议问题