In Anqi CMS template, how are `{{variable}}` and `{% tags %}` used for displaying dynamic content and logical control?

Calendar 👁️ 65

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

Related articles

How to reference static resources (such as CSS/JS/images) in AnQi CMS template to beautify content display?

In content operation, the aesthetics and user experience of the website are crucial, and this largely depends on the reasonable use and management of static resources (such as CSS stylesheets, JavaScript scripts, and images).For users who use AnQiCMS, mastering how to efficiently and standardizedly refer to these resources in templates is a key step to building a high-quality website.

2025-11-07

What is the organization method of the AnQi CMS template file to ensure the correct loading and display of content?

In AnQiCMS (AnQiCMS), the organization of template files is directly related to the correct loading, display efficiency, and subsequent maintenance convenience of website content.A clear and reasonable template structure that allows you to handle complex content display requirements with ease and greatly enhances team collaboration efficiency.The AnQi CMS uses Go language as the development foundation, its template engine syntax is similar to Django, which provides powerful and flexible tools for template developers.Understanding its core principles and following certain organizational standards will make your website operation twice as effective.

2025-11-07

How to use the Django template engine of Anqi CMS to create highly customized content display pages?

Today, with the increasing importance of digital content, how a website efficiently and beautifully presents its content is directly related to user experience and brand image.AnQiCMS (AnQiCMS) relies on its flexible and powerful Django template engine, providing infinite possibilities for highly customized content display pages.This article will delve into how to make use of the core capability of Anqi CMS to create content display pages that meet business needs and are uniquely crafted.

2025-11-07

Which website modes does AnQi CMS support to adapt to the display of content on PCs and mobile devices?

In this diverse digital age of devices, whether browsing news, shopping, or accessing services, users may visit websites through PCs, laptops, tablets, or smartphones.Therefore, whether your website content can be displayed clearly and beautifully on different screen sizes is directly related to user experience and brand image.AnQi CMS understands this core requirement and provides a variety of flexible website modes to ensure that your content is displayed in a perfect posture on any device.

2025-11-07

How to handle the UTF-8 encoding of Anqi CMS template to avoid garbled display of website content?

When using Anqi CMS to manage website content, you may occasionally encounter situations where乱码 appear on the page, which is usually related to the encoding settings of the template file.The AnQi CMS has specific requirements for the encoding of template files - it must use UTF-8 encoding uniformly.Understanding and properly handling this stage is the key to ensuring that the website content is displayed normally and provides a good browsing experience. Why do character codes appear乱码?

2025-11-07

How to set up a separate display template for specific documents, categories, or single pages in AnQi CMS?

In website operation, we often need to present distinctive design or functional layout for specific content (whether it is detailed documents, entire category pages, or independent single pages).AnQi CMS provides a flexible mechanism that allows users to easily specify independent display templates for this content, thereby achieving highly personalized website display effects. To understand how to set up an independent template, we first need to have a basic understanding of the template mechanism of Anqi CMS.

2025-11-07

How to create and store a mobile template in Anqi CMS to ensure the normal display of a mobile website?

Build and manage mobile templates in AnQiCMS to ensure your website displays correctly on mobile devices, you need to understand its flexible template adaptation mechanism and clear file storage rules.AnQiCMS provides various mobile adaptation modes, allowing you to choose the most suitable method according to your actual needs. ### Understanding AnQiCMS' Mobile Adaptation Mode Firstly, we need to understand the three main mobile adaptation modes supported by AnQiCMS: 1.

2025-11-07

How to display detailed information of a specific document in the Anqi CMS template, including the title, content, and thumbnail?

In AnQi CMS, sometimes we may need to display detailed information of a preset document at a specific location on the website, such as a recommendation area on the homepage or the '精选内容' module in the sidebar, including its title, content, and an eye-catching thumbnail.To achieve this goal, Anqi CMS provides a very flexible and intuitive way.

2025-11-07