How to set the default value for numbers or strings in Anqi CMS template if there are no values in numbers or strings?
default
Filters can set default values for numbers or strings if they have no values.
default_if_none
The filter can determine whether the object of the pointer type is empty. If it is empty, set the default value.
How to use
default
How to use filters:
{{ obj|default:default }}
For example, below, you can write this:
{{ nothing|default:"-" }} # Show results -
default_if_none
How to use filters:
{{ obj|default:default }}
For example, below, you can write this:
{{ nil|default_if_none:"n/a" }} # Display result n/a
Sample Demo
{{ simple.nothing|default:"n/a" }} {{ nothing|default:"-" }} {{ 42|default:"n/a" }} {{ 5|default:"n/a" }} # Show results n/a - 42 5
{{ simple.nothing|default_if_none:"n/a" }} {{ ""|default_if_none:"n/a" }} {{ nil|default_if_none:"n/a" }} # Show results n/a n/a