How to use AnQiCMS built-in tags to control content display logic?

Calendar 👁️ 69

In AnQiCMS, the built-in tag system is the core tool you use to control the display logic of website content.It provides a powerful and flexible syntax that allows you to control the acquisition, filtering, sorting, formatting, and final layout of content in template files without writing complex backend code.This system is similar to the Django template engine syntax, easy to learn, and can help you convert technical details into intuitive display effects.

Basic structure of AnQiCMS tags

The AnQiCMS tag system mainly consists of two basic elements:

  1. Variable output tag ({{ 变量名 }}): It is used to display data directly on the page, such as obtaining the article title{{ item.Title }}.
  2. Logical control label ({% 标签名 参数 %}): Used to handle various logic, such as conditional judgments, loop traversals, file imports, etc. These tags usually require a{% end标签名 %}Close it.

Understanding these two tags is the key to deeply using AnQiCMS templates. All tags and variables are strictly case-sensitive and must be consistent when used.

Retrieve and display content: data-driven display logic

AnQiCMS provides various tags to retrieve different types of content, you can choose the appropriate tag according to your needs:

  • List data acquisition:

    • archiveList: Used to obtain document lists under articles, products, and other models. You can setmoduleIdSpecify models (such asmoduleId="1"obtain articles),categoryIdFilter categories,limitControl the quantity,type="page|list"Choose pagination or a regular list,orderDefine sorting rules, etc.
    • categoryList: Get the category list. Often used to display navigation menus or sidebar categories. You can accessparentIdSpecify the parent category, even get the subcategory or sibling category of the current category.
    • pageListGet the single page list, such as "About Us", "Contact Us", etc.
    • tagListGet the tag list, often used to build popular tag clouds or related tags.
    • navListGet the website navigation menu configured in the background. Supports multi-level navigation.

    After you get the list data, you will usually combine{% for %}Loop tags to iterate and display one by one:

    {% archiveList archives with type="list" categoryId="1" limit="5" %}
        {% for item in archives %}
            <li><a href="{{ item.Link }}">{{ item.Title }}</a></li>
        {% empty %}
            <li>当前分类下暂无内容。</li>
        {% endfor %}
    {% endarchiveList %}
    

    The code will display the titles of the first 5 articles with category ID 1, if the list is empty, it will display 'No content under the current category.'

  • Detail-oriented data acquisition:

    • archiveDetailGet the detailed information of a single document. On the article detail page, it is usually not necessary to specify the ID, as it will automatically retrieve the document information of the current page. You can specifyname="Title"Get the title,name="Content"to get content, etc.
    • categoryDetailGet detailed information of a single category, such as category title, description, link, etc.
    • pageDetailGet detailed information of a single page.
    • tagDetailGet detailed information of a single tag.
    • systemGet global system settings, such as website nameSiteName, Website LogoSiteLogo, Record numberSiteIcpetc.
    • contactGet contact information configured in the background, such as phone numberCellphonephone, contact emailEmailetc.
    • tdkGet SEO information of the current page, such as titleTitle, keywordsKeywordsDescription,Description.

    These tags are usually used for page header SEO settings, detail page content display, or footer information display:

    <title>{% tdk with name="Title" siteName=true %}</title>
    <meta name="keywords" content="{% tdk with name="Keywords" %}">
    <meta name="description" content="{% tdk with name="Description" %}">
    
    <h1>{% archiveDetail with name="Title" %}</h1>
    <div>{{ archiveDetail with name="Content" | safe }}</div>
    

Logical control and conditional display

In content display, we often need to decide whether to display an element or what kind of content to display based on specific conditions.{% if %}Tags are the core of this logic:

  • Conditional judgment:

    {% if item.Thumb %}
        <img src="{{ item.Thumb }}" alt="{{ item.Title }}">
    {% else %}
        <img src="{% system with name="DefaultThumb" %}" alt="默认图片">
    {% endif %}
    

    This code will determine if the article has a thumbnail, if it does, it will display it, otherwise, it will display the default system thumbnail.

  • Multi-condition judgmentYou can use{% elif %}and{% else %}Handle more complex logic, such as determining user permissions, content types, etc.

Data formatting and conversion

AnQiCMS provides a series of filters (|) and dedicated tags to handle data formatting, ensure that content is presented in **style: World

  • Date and Time:stampToDateLabels can format timestamps into readable date and time strings. It should be noted that the format parameters follow the specific time formatting standards of the Go language (such as2006-01-02 15:04:05)

    <span>发布日期:{{ stampToDate(item.CreatedTime, "2006年01月02日") }}</span>
    
  • Text content processing:

    • |safeThis is a very important filter used to display content in a rich text editor or strings containing HTML tags.It can prevent HTML tags from being escaped, ensuring that the page renders correctly.
    • |truncatechars:N: Truncate the string to a specified number of characters and add "..." at the end
    • |default:"默认值": Display a predefined default value when the variable is empty or does not exist.
    • |render: If your content is in Markdown format, this filter can render it into HTML.
    • |replace:"旧词,新词": Replace a specific substring in a string.
    • |split:"分隔符"and|join:"分隔符": Used for conversion between strings and arrays.
    <p>{{ item.Description | truncatechars:100 }}</p> {# 截取前100个字符 #}
    <p>{{ item.Content | render | safe }}</p> {# 渲染Markdown内容并确保HTML正确显示 #}
    

Reusability and organization of template code

To improve efficiency and maintainability, AnQiCMS supports template inheritance, inclusion, and macro definitions:

  • {% include "路径/文件名.html" %}Insert the content of another template file at the current position. This is very suitable for reusing common modules such as headers, footers, and sidebars. You can also usewithPass the parameter to the included template.
  • {% extends "基础模板.html" %}and{% block 名称 %}: Implement template inheritance. You can define a basic layout (such as)base.html), which contains the page skeleton, and then the child template rewritesblockFill specific content without needing

Related articles

What template file extensions and storage locations does AnQiCMS support?

AnQiCMS as a flexible and efficient content management system provides powerful template customization capabilities.It is crucial to make full use of this advantage of AnQiCMS and understand the suffix and storage location of its template files.This can not only help you design websites more efficiently, but also locate and solve problems faster when encountering them.First, AnQiCMS template files use the `.html` suffix.This means that all template files you create or edit should be saved in HTML format. These`

2025-11-08

How to implement personalized display of front-end content in AnQiCMS?

In today's era of content overload on the internet, how to make a website stand out and provide a unique and valuable experience to visitors has become crucial.The personalized display of content is an important means to enhance user stickiness, conversion rate, and brand image.AnQiCMS as an efficient and customizable content management system provides many features to help us easily achieve this goal.The flexible construction of content models: the foundation of personalized display The first step in personalized display is to make our content inherently personalized.The flexible content model feature of AnQiCMS

2025-11-08

How to display the title and content of articles in AnQiCMS templates?

Manage website content in AnQiCMS, the ultimate goal is to be able to present this content to visitors in an elegant and efficient manner.For the most common content type of articles, how to accurately display the title and body in front-end templates is a basic skill that every website operator needs to master.AnQiCMS powerful template function, providing us with a flexible and intuitive implementation method.### Core: Get to know the `archiveDetail` tag AnQiCMS's template system is designed to be very user-friendly

2025-11-08

How to get the string in AnQiCMS template?

In AnQiCMS template development, text and strings are the foundation for building website content.Flexible and efficient string retrieval and manipulation are skills that template developers must master, whether it is to display article titles, website names, or process user input.AnQiCMS's powerful template engine is based on Go language, providing rich tags and filters, making string acquisition and processing intuitive and practical.### Core Mechanism: Understanding the String Retrieval Method of AnQiCMS Template The most direct way to retrieve strings in AnQiCMS templates is through variable references

2025-11-08

How does AnQiCMS adapt the display of website content for PC and mobile endpoints?

AnQiCMS: Providing seamless PC and mobile end adaptive display solutions for your website In today's digital age, it is common for users to access websites through various devices, from large computer screens to small smartphones, and the display effect of the website directly affects user experience and the efficiency of information transmission.A website that cannot be displayed friendliness on mobile devices will undoubtedly lose a large number of potential users and business opportunities.AnQiCMS fully understands this requirement and has provided flexible and diverse solutions to ensure that your website content is perfectly presented on both PC and mobile ends

2025-11-08

How to display the list of articles by category in AnQiCMS?

It is crucial to organize and display information efficiently in website content management.For users, being able to clearly browse article lists by different categories greatly enhances the access experience and also helps search engines better understand the website structure, thereby optimizing SEO effects.AnQiCMS (AnQiCMS) provides us with flexible and powerful tools, making this requirement easily accessible.

2025-11-08

How to set the number of articles or products displayed per page in AnQiCMS?

In website operation, especially when managing pages that require a large amount of content display, such as article lists and product display pages, how to efficiently control the number of items displayed per page directly affects user experience and page loading speed.AnQiCMS provides a flexible and powerful mechanism to meet this requirement, it allows you to customize the display of each page according to different page and content types through fine-grained control at the template tag level.The Anqi CMS can provide this flexibility because it closely integrates the display logic of the list content with the template design

2025-11-08

How to exclude content of a specific category from the article list?

In website content operation, we often encounter such needs: we hope to display most of the content on the article list page, but articles of certain specific categories are not listed here.For example, you may have a "Company Announcement" category that you only want to display on a separate page, or some articles for internal reference that you do not want to appear in the regular article list facing the public.AnQiCMS (AnQiCMS) provides a very flexible and intuitive way to handle this situation, allowing you to accurately control the display of content on the front end.The Anqi CMS through its powerful template tag system

2025-11-08