Twig: in_array or similar possible within if statement?

后端 未结 6 668
终归单人心
终归单人心 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:12

    Just to clear some things up here. The answer that was accepted does not do the same as PHP in_array.

    To do the same as PHP in_array use following expression:

    {% if myVar in myArray %}
    

    If you want to negate this you should use this:

    {% if myVar not in myArray %}
    

提交回复
热议问题