如何在Twig中检查字符串变量是否为null或空,或包含空格字符?(可能最短,可能相当于CSharp的String.IsNullOrWhiteSpace()
方法)
发布于 2014-04-10 15:33:51
发布于 2014-04-10 00:39:30
{% if your_variable is null or your_variable is empty %}
应检查变量是否为null或为空。
如果您想查看它是否为、非、null或not
,只需使用not
操作符。
{% if foo is not null and foo is not empty %}
请参阅文档:
也许您一般会对tests in twig感兴趣。
发布于 2014-09-12 18:40:23
我宁愿只使用和
{% if foo|trim is empty %}
{% if foo|trim is not empty %}
如果foo变量为:empty计算结果为true:
https://stackoverflow.com/questions/22968427
复制相似问题