Universal Template Tag
-
Other Auxiliary Tags
Some commonly used built-in tags.The nested reference in templates, include is often used when creating templates. We will extract some common parts, such as header, footer, aside, etc., and store them independently. We do not need to rewrite them on every page; we just need to include them in each page.At this moment, we can use the include tag. -
More Filters
When outputting variables, it also supports using filters to perform initial data filtering, the format is: {{obj|filter__name:param}} For example, a variable outputs the current value when it has a value, and outputs the default value when it does not have a value: Use default to set the default value: {{ userName|default:"Anonymous Guest"}} default is empty -
General Tag - Variable Assignment Tag
iris.The Django template engine's template parser provides a method named `with` that allows declaring variables and using them in templates.We can temporarily declare one or more variables with, providing them for later use.In most cases, we would use it in conjunction with the include tag. -
Timestamp Formatting Tag
In the template, it supports direct formatting of timestamps into specified formats.Label keyword: stampToDate.Usage method: {{stampToDate(time stamp, "format")}}.Timestamp in 10 digits, such as 1609470335, in the format supported by Golang. -
General Tag - For Loop Traversal Tag
for used to iterate over each item in an array, making the item available in the context variable. -
General Tag - Remove Logical Tag Lines
This requirement is often used, such as in if-elseif statements or for loops, it will also output the blank lines of the if-else label part. If you want to clean up these blank lines, you can use - before or after the label to filter them out, like: {%- if false %} 1st choice {%- elif false %} 2nd choice -
General Tag - Arithmetic Operation Tag
Using mathematical arithmetic to calculate integer and complex expressions in templates {{ 10-100 }} {{ -(10-100) }} {{ -(-(10-100)) }} {{ -1 * (-(-(10-100))) }} {{ -1 * (-(-(10-100))) -
General Tag - if logic judgment tag
The value of the label judgment expression, if the expression evaluates to true, then execute its main content.Usage method: {% if condition %} ... {% endif %} , {% if condition %} ...If other conditions {% elif other conditions %} ... {% endif %} , {% if condition %} ... -
Generate random text
The lorem tag can generate random text content of specified length.Generally used for typesetting needs.Usage method: {% lorem 数量 方法 random %} The number can be calculated by characters or words, depending on the method.The method is one of the following: 'w', 'p', or 'b'. -
Template text translation tag
Explanation: Used for translating specified text in the template.Usage method: {% tr variable name %} The prerequisite for using the translation field is that the template supports multi-language functionality.The method to enable multi-language function in the template is as follows: Create a directory named 'locales' under the template directory, and then create a folder with the name of the current language code, such as 'zh-CN' or 'zh-TW'.Create a yml file in the folder, for example, default.yml. -
Get multi-language site list tag
Description: Used to get the list of multilingual sites. Usage: {% languages variable_name %} For example, if the variable is defined as websites {% languages websites %}...{% endLanguages %} languages does not support setting parameters. languages will retrieve all multilingual sites.