Check if variable is string or array in Twig

后端 未结 4 569
暗喜
暗喜 2020-12-24 10:29

Is it possible to check if given variable is string in Twig ?

Expected solution:

messages.en.yml:

hello:
  stranger         


        
4条回答
  •  甜味超标
    2020-12-24 11:12

    Ok, I did it with:

    {% if title[0] is not defined %}
        {{ title|trans }}
    {% else %}
        {{ title[0]|trans(title[1]) }}
    {% endif %}
    

    Ugly, but works.

提交回复
热议问题