Defaults¶
Tpll offers a default collection of template tags and filters.
Default Tags¶
comment¶
Syntax:
{% comment %} ... {% endcomment %}
Ignores everything between {% comment %}
and {% endcomment %}
:
abra{% comment %} X Y {% endcomment %}cadabra
Outputs:
abracadabra
firstof¶
Syntax:
{% firstof arg1 arg2 arg3 ... %}
Returns the first argument that is not empty:
abra{% comment %} X Y {% endcomment %}cadabra
Outputs:
abracadabra
now¶
Syntax:
{% now %}
{% now format %}
Returns the current date and time. Accepts one argument with the desired format. The format must use the same syntax and codes defined by the formatTime function:
Date/Time: {% now %}
Outputs:
Date/Time: 2015-11-26 23:11:25
Specifying the format:
Date/Time: {% now "%Y-%m-%d" %}
Outputs:
Date/Time: 2015-11-26
for¶
Syntax:
{% for x in list %} ... {% endfor %}
{% for x in list %} ... {% empty %} fallback {% endfor %}
Iterates over all items in the list. If the list is empty, render the empty block if present:
{% for x in list %}{{ x }},{% endfor %}
Outputs:
1,2,3,5,
Catching empty lists with {% empty %}
:
{% for x in unknown %}{{ x }},{% empty %}foo{% endfor %}
Outputs:
foo
Default Filters¶
ljust¶
Syntax:
{{ arg|ljust }}
Left-aligns the value in a field of a given width:
{{ "foo"|ljust:10 }}
Outputs:
foo.......
Note: dots were used to represent whitespaces.
rjust¶
Syntax:
{{ arg|rjust }}
Right-aligns the value in a field of a given width:
{{ "foo"|rjust:10 }}
Outputs:
.......foo
Note: dots were used to represent whitespaces.