There are already good answers, but I give my 2 cents too:
{% if foo|length %}
I was inspired by @GuillermoGutiérrez's filter trick.
But I think |length
is safer as the "0"|trim
expression will evaluates to false.
References :
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…