Universal template tags
-
Other auxiliary tags
Some commonly used built-in tags. Nested references of templates. Include is often used when creating templates, we will extract some common parts, such as header, footer, aside, etc., and store them independently. There is no need to repeat them on each page, we just need to introduce them on each page. At this time, we can use include tag. {% include "par -
More filters
When outputting variables, filters are also supported to perform primary filtering of data. The format is: {{obj|filter__name:param}} For example, when a variable has a value, it outputs the current value. When there is no value, it outputs the default value: Use default to set the default value: {{ userName|default:"The hero anonymous"}} default as long as it is empty -
General tags - Define variable assignment tags
The template parser of the iris.Django template engine provides methods with which variables can be declared in templates and used. With we can temporarily declare single or multiple variables for subsequent use. In most cases, we will use it with the include tag. For example: {% with title="This is the title declared for the header" keywords="This is the sound -
Format timestamp tags
In the template, it supports direct formatting of timestamps into specified format output. Tag keyword: stampToDate. How to use: {{stampToDate(timestamp, "format")}}. The time stamp is 10 bits, such as 1609470335, the format is a format supported by Golang. Example: {% set publishStamp = 160947033 -
General tags - for loop traversal tags
for is used to iterate over each item in the array, making the item available in the context variable. For example, to display a list of articles provided in articleList: {% for item in articles %} <li class="item"> <a href="/article/{{item.Id}}" class="li -
General Tags - Remove logical tags to occupy rows
This requirement is often used, for example, in if-elseif or for loop, it will output empty lines of the rows in the if-else tag part. If you want to clean up this empty line, you can use - in front or behind the label to achieve filtering, such as: {%- if false %} 1st choice {%- elif false %} 2nd choice -
General tags - Arithmetic tags
integers and complex expressions using mathematical arithmetic in templates integers and complex expressions {{ 10-100 }} {{ -(10-100) }} {{ -1 * (-(-(-(10-100)) }} {{ -1 * (-(-(-(10-100)) }} {{ -1 * (-(-(-(10-100))) }} {{ -1 * (-(-(-(10-100))) -
General tag-if logical judgment tag
The tag determines the value of the expression. If the value of the expression is true, the body content will be executed. How to use: {% if condition %} ... {% endif %}, {% if condition %} ... {% elif Other conditions %} ... {% endif %}, {% if condition %} ... {% elif Other conditions %} ... {% elif Other conditions %} -
Generate random text
The lorem tag can generate random text content of a specified length. Usually used for typesetting needs. Usage method: {% lorem Quantity Method random %} The quantity can be calculated by the number of words or by the number of words, and it needs to be decided according to the method. The method is one of the following: 'w', 'p' or 'b'. random is whether it is random. If you fill in random, you will follow it if you fill in random. -
Template text translation tags
Description: Used for the specified text translation of the template. How to use: {%tr variable name %} The premise of using translation fields is that the template supports multilingual features. The multilingual function of a template is enabled as follows: Create the locales directory in the template directory, and then create a folder whose name is the code of the current language, such as zh-CN or zh-TW. Create a yml file in the folder, such as default.yml. The directory structure is as follows: ./locales ├── en-us │ └── -
Get multilingual site list tags
Description: Used to get a list of multilingual sites Used: {% languages variable name %} If you define a variable as websites {% languages websites %}...{% endLanguages %} languages does not support setting parameters languages will get all multilingual sites. websites is an array object, so you need to use a for loop to output item as a variable in the for loop body.