Skip to content

Latest commit

 

History

History
15 lines (8 loc) · 635 Bytes

File metadata and controls

15 lines (8 loc) · 635 Bytes

|default

如果过滤的值未定义或为空,则|default过滤器返回作为第一个参数传递的值,否则返回过滤的值。

{{ variable|default('The variable is not defined') }}

{{ variable.foo|default('The foo property on variable is not defined') }}

{{ variable['foo']|default('The foo key in variable is not defined') }}

{{ ''|default('The variable is empty')  }}

在某些方法调用中使用变量的表达式上使用default过滤器时,每当变量可以未定义时,请务必使用default过滤器:

{{ variable.method(foo|default('bar'))|default('bar') }}