AnQiCMS with its efficient and flexible features, has become a good helper for content management. The presentation of website content cannot be separated from templates, and in the AnQiCMS template system,{{变量}}and{% 标签 %}Is the core element to build dynamic pages and realize powerful functions. They bear different responsibilities and work closely together to make our website content come alive.


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

Imagine, what title of an article or the name of a website you would like to display on the page. In this case, we will use double curly braces.{{变量}}.Its main function is to directly output the processed data from the background to the webpage.You can consider it as a placeholder, AnQiCMS will replace this placeholder with actual data during page rendering.

For example, to display the title of the current article, you can use{{archive.Title}}To display the filing number of the website, you can write{{system.SiteIcp}}These variables usually follow camelCase naming conventions, with the first letter capitalized for easy identification. In addition to directly outputting text, numbers, and links,{{变量}}it can also handle more complex data types, such as image paths{{archive.Logo}}.

To present data in a more aesthetic and practical way,{{变量}}also supports powerful Filters functionality. Filters are used to|Symbol concatenation after variable names can be used to format, truncate, or convert data. For example, a timestamp{{item.CreatedTime}}Can be accessed{{item.CreatedTime|stampToDate:"2006-01-02"}}Convert to a readable date format; long text{{item.Description}}Can be accessed{{item.Description|truncatechars:100}}Extract a fixed number of characters and add an ellipsis to avoid content overflow. These filters make the data display more flexible and diverse.


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

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

Conditional judgment:{% if %}tags

The page content is not static, often requiring display or hiding of a certain block based on specific conditions.{% if 条件 %}Tags are born for this. You can use it to judge whether a variable exists, whether it is equal to a certain value, or perform more complex logical comparisons. For example,{% if archive.Id == 10 %}to display specific article content,{% else %}Show other.{% elif %}and{% else %}Provided multiple branch selection, making logical judgment more refined. This label needs to be{% endif %}to close.

Loop iteration:{% for %}tags

The website contains a large amount of content in list form, such as article lists, product lists, navigation menus, and so on.{% for item in collection %}Labels can iterate over each element in the collection and execute the same template code for each element. This greatly reduces the need for repetitive template code writing. For example, by{% archiveList archives with type="list" limit="10" %}Get a list of articles, then{% for item in archives %}display the title, summary information of each article one by one. Worth