Default value settings for numbers or strings and objects

How to set default values for numbers or strings, or objects without values in the Anqi CMS template?

defaultFilters can set default values ​​for numbers or strings if they have no values.

default_if_noneThe filter can determine whether the object of the pointer type is empty. If it is empty, set the default value.

How to use

defaultHow to use filters:

{{ obj|default:默认值 }}

For example, below, you can write this:

{{ nothing|default:"-" }}
# 显示结果
-

default_if_noneHow to use filters:

{{ obj|default:默认值 }}

For example, below, you can write this:

{{ nil|default_if_none:"n/a" }}
# 显示结果
n/a

Sample Demo

{{ simple.nothing|default:"n/a" }}
{{ nothing|default:"-" }}
{{ 42|default:"n/a" }}
{{ 5|default:"n/a" }}
# 显示结果
n/a
-
42
5
{{ simple.nothing|default_if_none:"n/a" }}
{{ ""|default_if_none:"n/a" }}
{{ nil|default_if_none:"n/a" }}
# 显示结果
n/a

n/a