How to use similar Django variable and tag syntax in AnqiCMS templates?

Calendar 👁️ 62

As an experienced CMS website operations personnel of an enterprise, I deeply understand the core status of content in the digital age.An efficient content management system, especially its template function, is the cornerstone to ensure that the website content can be presented flexibly and accurately to the readers.AnQi CMS performs very well in this aspect, it draws on the mature Django template engine syntax, allowing content creators and template developers to build pages in an intuitive and powerful way.

AnQi CMS template engine overview of Django-style syntax

The AnQi CMS template engine is cleverly designed, its syntax style is similar to that of the Django template engine in Python, and it also absorbs the concise characteristics of modern templates like Blade.This design aims to reduce the threshold of learning, allowing teams familiar with web development to quickly get started and efficiently create and manage website content.The template file is usually with.htmlas suffix, stored in/templatedirectory, its core lies in the output of variables and the application of logical control tags.

The data output in the template, which is a variable, is represented by double curly braces{{ 变量名 }}This style is consistent with many modern template engines, intuitive and easy to understand. For example, if you want to display the name of the website on the page, you simply write{{ system.SiteName }}. In Anqi CMS, variable names usually follow CamelCase, for examplearchive.TitleUsed to get the document title,system.SiteLogoUsed to obtain the website logo image address, such naming conventions help maintain code consistency and readability.

And for the logical control in the template, such as conditional judgment, loop traversal, etc., Anqi CMS uses the combination of single curly braces and percentages.{% 标签 %}These tags always appear in pairs, with clear start and end tags, such as{% if 条件 %} ... {% endif %}Used for conditional judgment,{% for item in 列表 %} ... {% endfor %}Used for loop traversal. This structure clearly defines the scope of the logic code block, making template maintenance and expansion more convenient.

Flexible application of variables and data presentation

The variables in Anqi CMS templates are carriers of dynamic page content.Through these variables, you can easily access system settings, article details, category information, user data, and more.For example, on the article detail page, you can{{ archive.Title }}Show the title of the current article through{{ archive.CreatedTime }}Get the timestamp of the article published and format it with a filter, or through{{ archive.Description }}Display the article summary.

For more complex data types, such as lists or arrays, you can also directly access their properties. For example, when you get a list containing multiple friendship linksfriendLinksyou can directly access through{{ item.Link }}and{{ item.Title }}Output the address and name of each link. The dot notation method of accessing properties simplifies the operation of data hierarchies..Strong control of tags and page structure construction.

Strong control of tags and page structure construction.

In addition to variables, the tag system of Anqi CMS is even more powerful in its template engine.They are not only used to control the logic flow of the page, but also to call various built-in functions, even to achieve the reuse and inheritance of templates.

Conditional judgment and loop traversal

The most basic logical control tag isifandfor.{% if 条件 %}The tag allows you to decide whether to render a specific content block based on the truth or falsity of a certain condition. For example,{% if item.Thumb %}Can determine if the article has a thumbnail, thereby deciding whether to display the image tag.{% for item in 列表 %}The tag is used to iterate over arrays or lists, processing each element one by one. In a loop, you can also useforloop.Counterto get the current loop index, or{% empty %}Tags to handle the case of an empty list, these are very practical features.

Built-in feature tags

The Anqi CMS is built-in with rich tags covering many aspects of website operation. For example,{% system with name="SiteName" %}you can directly obtain the name of the website,{% contact with name="Cellphone" %}and then you can get the preset contact phone number.{% archiveList archives with type="page" limit="10" %}It is the core tag for getting the article list and supporting pagination. It can flexibly display articles of different categories and sorting.{% pagination pages with show="5" %}It is used to render pagination navigation bars. These tags greatly improve the efficiency of template development through concise parameter configuration.

Auxiliary tags and filters

To further enhance the reusability and presentation of the template, Anqi CMS also providesinclude/extendsandmacroand other auxiliary tags.{% include "partial/header.html" %}Allow you to split the common parts of the page (such as the header and footer) into independent files and reference them where needed, to avoid code redundancy.{% extends 'base.html' %}Then template inheritance was implemented, you can define a general structure in the base template, and then overwrite specific content blocks in the child template to achieve unified website style and flexible changes of local content.{% macro 函数名(参数) %}You can define reusable code snippets that accept parameters and return rendered content, thereby improving the modularization of templates.

Moreover, filters are powerful tools for handling variable output formats. Through the pipe character|, you can pass a variable to one or more filters for processing. For example,{{ item.CreatedTime|stampToDate:"2006-01-02" }}The timestamp can be formatted into a readable date string,{{ content|safe }}which is used to declare that the content is safe HTML, preventing automatic escaping.{{ value|truncatechars:10 }}Can truncate strings to a specified length, which provides convenience for the refinement of content display.

Template production conventions and **practice.

It is crucial to follow some basic conventions when developing templates in AnQi CMS.The template file should use UTF-8 encoding to avoid garbled characters.The template directory structure is clear, static resources should be stored in/public/static/Under the catalog. Utilize.includeandextendsBuild a maintainable template structure, separate the common part and the variable area, which is the key to efficient development.At the same time, fully utilizing various built-in tags and filters can reduce the writing of custom logic, allowing the template to focus more on content display.

The Anqi CMS template engine, with its intuitive syntax similar to Django, provides a powerful and flexible tool for website operators and developers.Whether it is the daily content publishing or the adjustment of complex page layouts, it can be done with ease.


Frequently Asked Questions (FAQ)

1. Do AnQi CMS template tags distinguish between uppercase and lowercase?

Yes, AnQi CMS template tags and variables are strictly case-sensitive. For example,{{ archive.Title }}ofTitleIt must start with a capital letter to correctly retrieve the document title. Be sure to pay attention to the case of variable names and tag parameters when writing template code to avoid unnecessary errors.

2. How to deal with garbled characters in template files?

The template file is garbled usually due to incorrect file encoding.The AnqiCMS requires that all template files must use UTF-8 encoding.If you are editing template files in a Windows environment, please make sure that your text editor (such as Notepad++, VS Code) saves the file in UTF-8 format. Check.design-convention.mdDescription of file encoding in the document, and adjust your editing environment settings.

How to dynamically determine the current page type in the template (such as article detail page, category list page)?

The Anqi CMS template engine automatically loads the corresponding context data when rendering different pages.You can determine the type of the current page by checking if a specific variable or tag exists.For example, on the article detail page,archiveThe object (or any custom document variable you define) is usually filled, you can check{% if archive %}to determine if it is on the document detail page. Similarly, on the category list page,categoryor objectarchivesThe list will exist. Moreover, Anqin CMS also provides suchtdktags, and the output content will also adjust automatically according to the current page type.

Related articles

What are the basic conventions and directory structure specifications for AnqiCMS template creation?

Hello! As an experienced AnQiCMS website operator, I am very happy to share with you the key knowledge about AnQiCMS template creation.In my daily work, the reasonable planning and precise application of templates are the foundation for ensuring the efficient display of content and improving user experience.A deep understanding of the basic conventions and directory structure specifications of AnQiCMS templates not only allows us to create and publish content more smoothly, but also lays a solid foundation for the long-term maintenance and optimization of the website. Next

2025-11-06

What are the mainstream search engines supported by AnqiCMS's link push function?

As an experienced website operator, I am well aware of the importance of timely inclusion after content publication for website traffic and SEO performance.AnQiCMS (AnQiCMS) provides many conveniences in content management, among which the link push function is a key factor in helping website content be quickly discovered by search engines.This article will introduce in detail the link push function supported by Anqi CMS, including the main search engine types and their configuration methods, aiming to help website operators better utilize this feature and improve the inclusion efficiency of the website.###

2025-11-06

How does AnqiCMS support Markdown editor and display mathematical formulas and flow charts?

AnqiCMS as an efficient and customizable content management system, has always been committed to providing convenient and powerful creation tools for content operators.In daily content operations, we know that high-quality, clear, and expressive content is the key to attracting and retaining users.For this, AnqiCMS has continuously evolved and now fully supports Markdown editors, can elegantly present complex mathematical formulas and intuitive flowcharts, greatly enriching the dimensions of content expression, and making our website stand out in the sea of information

2025-11-06

How does the homepage TDK setting affect the title, keywords, and description optimization of the website?

AnQi CMS is an enterprise-level content management system designed for small and medium-sized enterprises, self-media operators, and users with multi-site management needs, one of its core advantages lies in its deep support for search engine optimization (SEO).In website operation, the setting of the home page TDK (Title, Description, Keywords) is the cornerstone of SEO work, which directly determines the first impression and preliminary performance of the website on the search engine results page (SERP).At Anqi CMS backend

2025-11-06

How to fetch the document list according to category ID, recommendation attributes, etc. for the `archiveList` tag?

As a senior security CMS website operator, I am well aware that the flexibility and powerful functions of the content management system tags are the key to efficient content operation.`archiveList` tag is the core tool used in AnQiCMS to retrieve document lists. The subtle use of its parameters can help us accurately present the desired content, whether it's building the recommended articles for the homepage, displaying specific documents on category pages, or providing related recommendations on detail pages, all of which rely on our proficiency with this tag.###

2025-11-06

How to get the detailed information of a specified document, including custom fields, using the `archiveDetail` tag?

In the daily operation of AnQi CMS, obtaining and displaying detailed information of website content is one of the core tasks.The `archiveDetail` tag is a powerful tool specifically designed for this purpose in the Anq CMS template system, allowing us to flexibly extract detailed data from any specified document, including standard document properties and user-defined field content.

2025-11-06

How to get the category list and detailed information of a single category with the `categoryList` and `categoryDetail` tags?

As a senior AnQi CMS website operation personnel, I know that the flexibility of content organization and presentation is crucial for attracting and retaining users.The site classification structure is not only the skeleton of content, but also an important path for users to explore and discover information.Today, let's delve deeply into the two core template tags in Anqi CMS, `categoryList` and `categoryDetail`, and how they help us efficiently obtain and display category lists and individual category details.## Flexible Construction of Category Navigation: `categoryList`

2025-11-06

How to display all tags and document lists under tags in `tagList` and `tagDataList` tags?

As an experienced website operator who deeply understands the operation of Anqi CMS, I fully understand the core role of content organization and user experience in the success of a website.Tags are the important bridge connecting these two, they not only help us effectively classify and manage a vast amount of content, but also guide users to quickly find the information they are interested in.In Anqi CMS, the `tagList` and `tagDataList` template tags are the key tools to achieve this goal, allowing us to flexibly display tags and associated documents under the tags on the website front-end.###

2025-11-06