What is the difference between the `{{variable}}` and `{% tag %}` syntax in AnQiCMS templates?

Calendar 👁️ 85

When using Anq CMS to build a website, templates are the key to dynamic content display. We often see two special syntax structures in template files:{{变量}}and{% 标签 %}.Although they are all related to the display and processing of data, they play different roles and are used in different ways.Understanding the difference between them is the first step to efficiently using the Anqi CMS template.

{{变量}}: Placeholder for dynamic content output

Imagine{{变量}}It is like a fill-in-the-blank question on a web page.Its main function is to directly output the data passed from the backend to the web page.When you want to display dynamic information such as article titles, website names, and user comments on a page, this syntax is used.

For example, if you want to display the current article title on a page, you might see something like this:{{archive.Title}}. Here,archiveIt may represent the current article object, andTitlewhich is the title attribute of the article object. Similarly, to display the website filing number, you can directly use{{system.SiteIcp}}. Through the dot (.), we can delve into the properties of the object layer by layer.

It is worth mentioning that variables can also be processed through filters before output, such as truncating text, converting case, and formatting dates, etc. For example,{{ item.Title|truncatechars:10 }}It will truncate the first 10 characters of the article title and output. And like{{stampToDate(item.CreatedTime, "2006-01-02")}}This style, although it looks like a function call, it is still based on a variable, and it formats the value (timestamp) through a built-in function, finally outputting the processed variable content.These filters make the output of variables more flexible and diverse, meeting various display requirements.

{% 标签 %}: Control logic and instructions to obtain complex data

Compared with that,{% 标签 %}It is more like a set of instructions or a functional module.It does not directly output data, but is used to control the logical structure of templates, execute specific operations, or retrieve complex data sets.The core lies in 'control' and 'function'.

{% 标签 %}Is very widely used, for example:

  • logical judgment: When you need to decide whether to display a certain content based on a condition, you can use{% if 条件 %}...{% endif %}For example,{% if archive.Id == 10 %}这是文档ID为10的文档{% endif %}specific content will be displayed when the document ID is 10.
  • Loop throughWhen you need to iterate over a list or array and render each item repeatedly, you will use{% for item in list %}...{% endfor %}For example,{% for item in archives %}You can loop through each article in the article list.
  • Data acquisition and processing: Anqi CMS provides a rich set of built-in tags to retrieve specific types of data sets. For example,{% navList navs %}tags to retrieve the navigation list of the website,{% archiveList archives with type="page" %}It is used to obtain a paginated list of articles. These tags are usually needed to be used in conjunction{% for %}in a loop to iterate and use{{变量}}to output the specific content.
  • Other auxiliary functions: Some tags are used for the organization structure of templates, for example{% include "partial/header.html" %}Used to introduce other template file fragments,{% extends 'base.html' %}For template inheritance, etc.

These tags often appear in pairs, for example{% for %}Always with{% endfor %}End,{% if %}Always with{% endif %}End, clearly defining their scope.

The core difference: content and instructions

Fundamentally,{{变量}}and{% 标签 %}The core difference lies in the roles they play:

  • {{变量}}The task isDisplay data. It is a pure output mechanism, displaying the values provided by the backend directly on the page, or after simple filtering.
  • {% 标签 %}The task isExecute commands, control logic, or retrieve complex dataIt is a functional structure used to build the logical skeleton of a page, handle data flow, rather than directly display a specific value.

In simple terms,{{变量}}is the concrete embodiment of content, while{% 标签 %}Is a tool and set of rules for handling, organizing, and determining when and where content appears.Mastering the essence of these two grammars allows you to effortlessly control the Anqi CMS template system, whether it is to display simple content or build complex dynamic pages, you can do it with ease, making website operation twice as efficient.


Frequently Asked Questions (FAQ)

Question:{{变量|过滤器}}and{% 标签 参数 %}Can handle data, what are the differences?

Answer: {{变量|过滤器}}Mainly forAlready existsFormat or convert a single variable value, its role is to beautify and adjust the display of data.For example, shorten a long article abstract or convert timestamps to readable date formats.The processing range is usually limited to the value of the variable itself.

And{% 标签 参数 %}Has a more extensive function, it may be used forObtainData (for examplearchiveListGet the list of articles, perform complex logical judgments (for example)ifsentences), or generate structured content (for example)paginationGenerate pagination navigation).The function is to organize and control the display of content, sometimes it also includes internal data processing logic, but its core is 'function' or 'control', rather than just the 'formatting' of a single variable.

Question: All tags are required{% end标签 %}?

Answer:Tags are not required for all. Usually, used to control logical flow (such asif/for) or handle complex data sets (such asnavList/archiveListThe tag needs an ending tag to define its scope. But some tags, such as{% system %}or{% contact %}(when they directly output field values), or like{% lorem %}This tag for generating random content does not require an end tag. Whether an end tag is needed is usually specified in the AnQiCMS tag usage documentation.

Ask: Can I customize new{{变量}}or{% 标签 %}?

Answer:As a regular user, you usually cannot customize the new core directly in the template file{{变量}}or{% 标签 %}syntax itself.{{变量}}The value is usually provided by the backend code, while{% 标签 %}It is a system built-in control structure or functional module.

However, Anqi CMS provides the function of "custom content model fields" and "custom setting parameters", and you can use these fields defined in the background to expand{{变量}}The content, such as adding a custom field for the "author biography" in the template, and then passing through{{archive.AuthorIntro}}Call. Or use existing tags and filters to create a more personalized display, such as using first{% archiveList %}Get the list of articles, then use{% for %}Loop through and pass through{{ item.Title|upper }}To display uppercase titles and achieve customization effects.

Related articles

How to get the associated document list based on Tag ID and how to paginate it for `tagDataList` tags?

In website content operation, effectively organizing and displaying related content is crucial for improving user experience and the SEO performance of the website.AnQiCMS (AnQiCMS) provides powerful tag features, where the `tagDataList` tag is the key tool to help us achieve this goal.It can flexibly retrieve all related document lists based on the specified tag ID, and easily achieve content pagination display by coordinating with other tags.

2025-11-08

How to use the `tagDetail` tag to get the detailed information of a Tag, such as description and link?

In AnQi CMS, tags (Tag) are an important tool for organizing content, improving SEO, and enhancing user experience.Sometimes, we need not only to list tags, but also to display detailed information about a specific tag on the page, such as its description, link, and even Logo.At this moment, the `tagDetail` tag comes into play, helping us easily obtain this data.

2025-11-08

How to call the Tag list of the specified document in AnQiCMS template?

In AnQiCMS, tagging content (Tag) is an effective way to enhance content organization and user experience.These tags not only help search engines better understand the page theme, but also guide users to discover more related content.When you need to display the Tag list associated with a specific document in a template, AnQiCMS provides an intuitive and powerful `tagList` tag to make this operation very simple.

2025-11-08

How to add and manage multiple Tag tags in AnQiCMS?

In a content management system, effectively organizing and presenting information is the key to improving user experience and search engine performance.AnQiCMS provides a flexible Tag feature, which allows for more refined categorization of content, making it easier for users to quickly find content of interest and also provides strong support for website SEO optimization.This article will provide a detailed introduction on how to add and manage multiple Tag tags in AnQiCMS, and discuss its practical value in content operation.

2025-11-08

How to define and use custom variables in AnQiCMS templates, such as the `{% with %}` tag?

In the template design of AnQi CMS, we often encounter scenarios where we need to temporarily store or pass data.In order to make the template code clearer, easier to read, and more powerful, AnQi CMS provides the mechanism for defining and using custom variables, the most commonly used of which are the `{% with %}` tag and the `{% set %}` tag.They can help us handle data flexibly in templates, avoiding repeated calculations or passing complex objects.

2025-11-08

How does AnQiCMS's 'Full Site Content Replacement' feature efficiently handle content strategy adjustments?

Today, with the increasing refinement and diverse strategies of content operation, how to adjust website content efficiently and accurately is a challenge facing every website operator.When brand information is updated, external link adjustments, or SEO strategy iterations occur, manually modifying thousands of contents on the website one by one is not only time-consuming and labor-intensive, but also prone to errors.Fortunately, AnQiCMS provides an extremely powerful tool - the "Full Site Content Replacement" feature, which can help operators with amazing efficiency and accuracy to deal with various content updates and strategy adjustments, and become a "secret weapon" for content management strategy adjustments.###

2025-11-08

How to configure the pseudo-static rules in AnQiCMS to optimize URL structure and include categories, model aliases?

Building a clear, search engine-friendly URL structure in AnQiCMS is a very important aspect of website operation.By reasonably configuring the pseudo-static rules and cleverly integrating categories and model aliases, not only can it enhance the user experience, but it can also significantly optimize the website's SEO performance.AnQiCMS as a high-performance content management system provides flexible pseudo-static features, allowing us to easily achieve these goals.The importance of optimizing URL structure Imagine you visit a website and see this kind of link: `example

2025-11-08

How to configure a separate domain and database information for a new site in AnQiCMS multi-site management?

AnQiCMS with its efficient and flexible multi-site management function provides great convenience to users, especially in scenarios where independent sites need to be built for different brands, products, or services.When you want to configure a separate domain and database information for a new site, AnQiCMS provides a clear and practical management process.This not only helps to isolate and secure the data, but also allows each site to have more independent operation and optimization space.### Understand the value of independent configuration for multiple sites Before discussing the specific operations

2025-11-08