Is there a Twig shorthand syntax for outputting conditional text

前端 未结 3 1340
有刺的猬
有刺的猬 2021-02-02 04:51

Is there a shorter syntax in Twig to output a conditional string of text?

{% if not info.id %}create{% else %}edit{% endif %}

3条回答
  •  半阙折子戏
    2021-02-02 05:48

    The null-coalescing operator also working, like:

    {% set avatar = blog.avatar ?? 'https://example.dev/brand/avatar.jpg' %}
    

提交回复
热议问题