How to use AnQiCMS template tags correctly to avoid common errors?

Calendar 👁️ 63

AnQiCMS provides a powerful and flexible template system, allowing highly customizable display of website content.Its template tag syntax is based on the Django template engine and combines the ease of use of Blade templates, making it easy for users unfamiliar with the Go language to get started quickly.However, to fully exploit the potential of template tags and avoid common mistakes, it is crucial to understand their correct usage and potential pitfalls.

AnQiCMS template tag basics: Understanding core syntax and conventions

AnQiCMS template files are usually named with.htmlwith suffix, stored in/templatedirectory. The core syntax for handling data output and logic control in the template is double curly braces{{变量}}With a single curly bracket and a percentage sign{% 标签 %}.

  • Data output ({{变量}}): Used to display data directly, for example{{archive.Title}}It will output the title of the article. Variable names usually follow camel case naming conventions, for exampleId/Title/CreatedTimeetc.
  • Logical control ({% 标签 %}): Used to implement conditional judgments, loop traversals, file imports, and other functions. These tags must appear in pairs, with start and end tags, such as{% if 条件 %}...{% endif %}or{% for item in 列表 %}...{% endfor %}.

In actual use, template files will also cooperate/public/static/The directory contains CSS, JavaScript, images, and other static resources.To ensure that the template can be parsed correctly, all template files should be saved using UTF-8 encoding.

AnQiCMS also supports some default template file naming conventions, such as document lists can be named{模型table}/list-{分类id}.html, and single pages can be namedpage/{单页面id}.html. Understanding these conventions helps us better organize template files and achieve personalized display of specific page content.

Key strategies to avoid common errors.

To use AnQiCMS template tags correctly and avoid common problems, the following aspects are particularly worth paying attention to:

  1. Case sensitivity is strictly required: AnQiCMS template tags and variable names are case-sensitive. For example,{{archive.id}}and{{archive.Id}}are two different variables. The tag names likearchiveListandarchivelistAlso, do not mix them up. A tiny spelling error can cause the tag to be unrecognized or the data to not display normally.
  2. Correct closing of the tag: All logical control tags (such as{% if %}/{% for %}/{% archiveList %}Tags must have corresponding closing tags{% endif %}/{% endfor %}/{% endarchiveList %}Forgetting to close the tags is a common mistake made by beginners, which can lead to template parsing errors and even cause web pages to crash.
  3. Accurate passing of parameters: Many tags require parameters to specify what data to retrieve or how to process. For example,{% archiveDetail with name="Title" id="1" %},nameParameters specify the fields to retrieve,idThe parameter specifies the article ID. Different tags support different parameters, be sure to consult the relevant documents to ensure the correctness of the parameter name and value range. Pay special attention.moduleId/categoryId/type/limitThe usage of commonly used parameters.
  4. The replacement of old and new tags: AnQiCMS is inv2.1.1Version, the template tags were reconstructed, and the original tags were removed.articleandproductTags were unified and added.archiveLabel. This means that if your website has been upgraded from an old version or has referred to the old tutorial, it still usesarticleListorproductDetailtags, it will cause an error. It is imperative to use the newarchiveList/archiveDetailtags for the unifiedarchiveSeries tags.
  5. Matching data type and filter.: Sometimes, data formatting or processing is required when outputting data.
    • Timestamp conversion:CreatedTimeandUpdatedTimefields usually return Unix timestamps and need to bestampToDatetag to format them as readable dates such as{{stampToDate(item.CreatedTime, "2006-01-02 15:04")}}.
    • safe output of HTML content: Article details (archive.Content) categorization content (category.ContentFields such as ")"}In order to correctly parse HTML, you need to use|safeFilter, for example{{archive.Content|safe}}.
    • Markdown content renderingIf the content is written in Markdown, it will be automatically converted when the Markdown editor is turned on. To manually control the conversion, you can addrenderParameters, or use|renderFilter, for example{{archive.Content|render|safe}}.
    • Content extraction: For long texts, you can use|truncatechars:100(Character truncation) or|truncatewords:50(Cut by words) and other filters to truncate and add ellipses.
  6. Understanding based on context: Some tags (for example)archiveDetail/categoryDetail) are attempted to be automatically retrieved when no explicit parameters are specified.idortokenThis is used on the document detail page.archiveDetailIt will automatically retrieve the current document data, but when used on the homepage, it needs to be explicitly specifiedidto retrieve the data of a specific document
  7. Correctly refer to static resources and template pathsIn the template, when referencing static resources (images, CSS, JS), you should use{% system with name="TemplateUrl" %}tag to get the root path of the static resources of the current template, for example<link href="{% system with name="TemplateUrl" %}/css/style.css" rel="stylesheet">.includeWhen using other template fragments, the path should also be correct, for example{% include "partial/header.html" %}.

Practical Guide: The correct way to open common tags

AnQiCMS provides rich tags, the following lists some commonly used tag usage methods and points out the places that need attention:

  • Global information acquisition (system,contact,tdk):

    • {% system with name="SiteName" %}Get the website name. This type of tag is usually not requiredendTag, output the result directly.
    • {% contact with name="Cellphone" %}Get the contact phone number. You can customize the name for convenience when calling, such as{% contact myPhone with name="Cellphone" %}{{myPhone}}.
    • {% tdk with name="Title" siteName=true %}Get the page title and you can choose whether to append the website name.siteNameThe parameter only applies toTitleTake effect.
  • Content list and details (archiveList,archiveDetail,categoryList,categoryDetail,pageList,pageDetail):

    • Article/Product list:{% archiveList archives with moduleId="1" type="page" limit="10" %}
      • moduleId: Specify the content model ID (such as1For article,2For product). This is a very important filtering condition.
      • typeIt can be.list(Fixed quantity list) orpage(Paging list).
      • limit: Limit the number of displayed items. Fortype="page", needs to be matched{% pagination %}label usage
      • categoryId: Specify the category ID. Multiple IDs are separated by commas.
      • Use within the loop,forTag traversalarchivesthrough.{{item.Title}}/{{item.Link}}etc. to obtain fields.
    • article/product details

Related articles

Does the statistics code tag support loading based on user role or login status?

In website operation, data statistics is the core to understand user behavior, optimize content strategy, and improve conversion rate.However, not all user data needs to be tracked in the same way, especially for internal team members, administrators, or specific VIP users, where we may want to avoid mixing their behavioral data into public-facing statistical reports or load statistical codes for specific user groups due to privacy considerations.For AnQi CMS users, a common and very practical question is: Can we flexibly decide whether to load the page statistics code based on user roles or login status?

2025-11-07

Does AnQi CMS provide the ability to integrate statistical code required for A/B testing?

The AnQi CMS is an efficient and customizable content management system, playing an important role in website operations.When it comes to the statistical code integration capabilities required for A/B testing, although Anqin CMS itself does not directly provide an integrated A/B testing platform and traffic distribution logic, its design philosophy and rich features provide a solid foundation and high flexibility for integrating third-party A/B testing tools. Understanding this question requires looking at it from two levels: first, the embedding of statistical code, and secondly, the creation and management of page variants required for A/B testing.

2025-11-07

Does the 'Traffic Statistics and Spider Monitoring' feature consume a lot of server resources?

As website operators, we are always pursuing data growth while also being vigilant about any factors that may slow down the website speed.Especially when it comes to modules that need to collect and process a large amount of data in real time, such as traffic statistics and crawler monitoring, performance consumption is often our biggest concern.In the end, even if a feature is powerful, it is not worth it if it sacrifices the website's access speed.Then, will the built-in traffic statistics and crawler monitoring function of AnQiCMS (AnQiCMS) also cause the server to be overloaded and become a potential bottleneck for website performance?My opinion is, there is no need to worry too much

2025-11-07

How can I smoothly switch the 'Statistics Code Tag' in Anqi CMS to replace the existing statistical code?

As a website operator, we often need to adjust or replace the statistical code used on the website based on business development and data analysis needs.Whether it is to migrate from the old statistical platform to the new platform, or to introduce more refined data tracking, this process requires us to complete the switch efficiently and smoothly, avoiding any interference with the normal operation of the website.The AnQi CMS fully considered these operational flexibility aspects from the outset, providing a very convenient "Statistics Code Tag" feature, making it extremely simple and safe to replace existing statistics code.Let's take a look together

2025-11-07

How to write AnQiCMS templates according to Django template engine syntax rules?

AnQiCMS (AnQiCMS) is an efficient and customizable content management system, with its powerful template engine being the core for achieving diverse website presentations.The template engine adopted by the system is highly similar to Django's syntax rules, which allows users familiar with web development to get started faster, even beginners can gradually master the skills of template writing through the guidance of this article.

2025-11-07

What is the difference between the variable output and logic control tags in AnQiCMS templates?

In AnQiCMS template development, we often deal with two core template elements: variable output tags and logical control tags.They all serve to present dynamic content to the user, but there are essential differences in their functional positioning, syntax form, and actual effects.Understanding and mastering their similarities and differences is the key to efficiently building AnQiCMS website templates.### Variable output label (`{{ ... }}`): The direct window for data display Imagine that your website is a beautiful showcase, and the variable output label is like the merchandise displayed in the showcase

2025-11-07

How to include external HTML fragments in AnQiCMS templates?

When building website templates in AnQiCMS, we often encounter some HTML code blocks that need to be reused, such as the website header, footer, sidebar navigation, advertisement slots, or some general content modules.If each time you repeat writing these codes in different template files, it is not only inefficient but also very麻烦 to find and update them one by one when modifications are needed.

2025-11-07

How to implement page skeleton reuse through inheritance in AnQiCMS templates?

In website construction and operation, we often face a challenge: how to ensure the consistency of the overall style of the website while being able to flexibly modify the specific content of each page, and at the same time, taking into account the development efficiency and the convenience of later maintenance?AnQiCMS provides a powerful and intuitive template inheritance mechanism, which is the core of solving these problems.It's like creating a "template" for your website, allowing you to easily reuse common structures and focus on content creation.

2025-11-07