Universal Template Tag
-
Other auxiliary labels
Some commonly used built-in tags. The nested reference to include is often used when making templates. We will extract some common parts, such as header, footer, and aside, and store them independently. There is no need to repeat the writing on each page, just need to include them on each page.At this time, we can use the include tag.{% include "par" -
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, when it has a value, will output the current value, and when it has no value, it will output the default value: Use default to set the default value: {{ userName|default:"Anonymous Hero"}} default is empty -
General label - Variable definition and assignment label
iris.Django template engine's template parser provides a method called with that allows declaring and using variables in the template.With we can temporarily declare one or more variables for subsequent use.In most cases, we will use it with the include tag.As: {% with title="This is the title declared for the header" keywords="This is the keyword" -
Formatted timestamp label
In the template, it supports directly formatting timestamps into specified formatted output.Label keyword: stampToDate. Usage: {{stampToDate(timestamp, "format")}}.A timestamp of 10 digits, such as 1609470335, in the format supported by Golang.Example: {% set publishStamp = 160947033 -
General Label - for loop traversal label
for used to iterate over each item in an array, making the item available in the context variable.For example, to display the article list provided by articleList: {% for item in articles %} <ul class="item"> <a href="/article/{{item.Id}}" class="li" -
General label - Remove logic label occupied line
This requirement is often used, such as in if-elseif or for loops, it will even output the blank lines of the if-else label part. If you want to clean up the blank lines, you can use - before or after the label to filter, such as: {%- if false %} 1st choice {%- elif false %} 2nd choice -
General label - Arithmetic operation label
In the template, use mathematical arithmetic to calculate integer and complex expressions {{ 10-100 }} {{ -(10-100) }} {{ -(-(10-100)) }} {{ -1 * (-(-(10-100))) }} {{ -1 * (-(-(10-100))) -
General Label - if logical judgment label
The value of the label judgment expression, if the value of the expression is true, then execute its main content.How to use: {% if condition %} ... {% endif %}, {% if condition %} ... {% elif other conditions %} ... {% endif %}, {% if condition %} ... {% elif other conditions %} -
Generate random text
The lorem tag can generate random text content of specified length.Generally used for typesetting needs. Usage: {% lorem quantity method random %} The quantity can be calculated by the number of characters or words, depending on the method.The method is one of the following: 'w', 'p' or 'b'.random for whether random, default not filled, fill in random and it will be random -
Translation label for template text
Description: Used for translating specified text in templates. Usage: {% tr variable_name %} The use of translation fields is subject to the template supporting multi-language functionality.The method to enable multi-language functionality in the template is as follows: Create a 'locales' directory under the template directory, and then create a folder named after the current language code, such as zh-CN or zh-TW.Create a yml file in the folder, for example, default.yml.Directory structure is as follows: ./locales ├── en-us │ └── -
Get the list of multilingual site labels
Instructions: Used to obtain a list of multilingual sites. Usage: {% languages variable name %} For example, define the variable as websites {% languages websites %}...{% endLanguages %} languages does not support parameter settings, languages will retrieve all multilingual sites.websites is an array object, therefore you need to use a for loop to output item as the variable within the for loop body -
Prevent the template engine from parsing the content inside the tag
The `{% verbatim %}` tag is used to prevent the template engine from parsing the content within the tags.Main function 1. -
Format Price Tags
AnQiCMS v3.5.6 version and later supports, older versions do not support Due to AnQiCMS's price field using the fen as the unit, it is not suitable for direct display output to the template, therefore, the price needs to be converted to yuan before output, the default output is more complex, it needs to be converted to float64 first, then divided by 100, and then formatted to two decimal places output{%- set price = item.Price|float/100 %}\u0026lt;span>${{price|floatformat