AnQiCMS with its efficient and flexible features has become a good helper for content management. The presentation of website content cannot do without templates, and in the template system of AnQiCMS,{{变量}}and{% 标签 %}The core elements for building dynamic pages and realizing powerful functions. They each have different responsibilities and work closely together to make our website content come alive.


{{变量}}: The intuitive presentation of data

Imagine, you want to display the title of an article on a page or the name of a website. That's when we use the double curly braces{{变量}}. Its main function is to directly output the processed data from the background to the web page.You can consider it as a placeholder, AnQiCMS will replace this placeholder with actual data when rendering the page.

For example, to display the title of the current article, you can use{{archive.Title}}; To display the record number of the website, you can write{{system.SiteIcp}}These variables usually follow camel case naming, with uppercase first letters for easy identification. Besides directly outputting text, numbers, and links,{{变量}}it can also handle more complex data types, such as image paths{{archive.Logo}}.

To present the data in a more aesthetic and practical way,{{变量}}it also supports powerful Filters function. Filters go through|The symbol concatenates after the variable name, which can format, truncate, or convert data. For example, a timestamp{{item.CreatedTime}}Can pass through{{item.CreatedTime|stampToDate:"2006-01-02"}}Converted to a readable date format; long text{{item.Description}}Can pass through{{item.Description|truncatechars:100}}Truncate a fixed number of characters and add an ellipsis to avoid content overflow. These filters make data display more flexible and diverse.


{% 标签 %}The art of logic and control:

If we say{{变量}}Responsible for what is displayed, then{% 标签 %}It is responsible for 'how to display' and 'when to display'. It is mainly used to implement logical control, loop iteration, conditional judgment, and call various built-in functions.

Conditional judgment:{% if %}Tag

The page content is not immutable, often it needs to be displayed or hidden according to specific conditions.{% if 条件 %}The label is born for this. You can use it to determine if a variable exists, whether it is equal to a certain value, or to perform more complex logical comparisons. For example,{% if archive.Id == 10 %}Display specific article content,{% else %}Display other.{% elif %}and{% else %}It provides multiple branch options to make logical judgments more refined. This label needs to be used.{% endif %}Close it.

Loop iteration:{% for %}Tag

The vast amount of content on the website is in list form, such as article lists, product lists, navigation menus, etc.{% for item in collection %}Labels can traverse each element in the collection and execute the same template code for each element. This greatly reduces the need to rewrite template code. For example, by{% archiveList archives with type="list" limit="10" %}Get a list of articles and then{% for item in archives %}Display the title, introduction, and other information of each article one by one. It is worth