Is it possible to check if given variable is string in Twig
?
Expected solution:
messages.en.yml
:
hello:
stranger
Can be done with the test iterable
, added in twig1.7, as Wouter J stated in the comment :
{# evaluates to true if the foo variable is iterable #}
{% if users is iterable %}
{% for user in users %}
Hello {{ user }}!
{% endfor %}
{% else %}
{# users is probably a string #}
Hello {{ users }}!
{% endif %}
Reference : iterable