How can I check if a string variable is null or empty, or full with space characters in Twig? (Shortest possible, maybe an equivalent to CSharp's String.IsNullOrWhiteSpace()
method)
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 :