What are the basic syntax rules of the AnQiCMS template engine used to display content?

Calendar 👁️ 104

AnQiCMS provides a user-friendly and powerful template engine, its design philosophy is to make the display of website content both flexible and easy to use.If you are familiar with template syntax such as Django or Blade, then AnQiCMS's template engine will be very familiar to you.It is committed to presenting complex backend data in a clear and readable manner on the website front end, allowing content operators to focus on content creation and optimization, rather than getting bogged down in code details.

Core syntax of template engine: The foundation for building content display

The basic syntax of AnQiCMS template engine revolves around two types of tags:

  1. Variable output:When you need to display data or content directly on the page, you will use double curly braces{{ 变量名称 }}For example, you may see the name of the website displayed.{{ siteName }}Such a mark. It is worth noting that variables in the template usually follow the camel case naming convention, that is, the first letter of each word is capitalized, for examplearchive.Titleorcategory.Link.

  2. Logic and control flow:For more complex display logic, such as conditional judgment (if a certain condition is met, a certain section of content is displayed) or loop (traversing a group of data and displaying each one in turn), the template engine provides a single curly brace and percentage sign marking method{% 标签名 参数 %}These tags usually need to appear in pairs, and if there is a start tag, there must be an end tag, such as{% if 条件 %}...{% endif %}or{% for item in list %}...{% endfor %}This ensures the integrity of the logical block.

On the organization of template files, AnQiCMS agrees to use.htmlas the suffix of template files, and store them uniformly in the site's/templateIn the directory. While images, CSS styles, JavaScript scripts, and other static resources are stored separately./public/static/In the catalog. To ensure the page displays normally, all template files should use UTF8 encoding.

Flexible content display: common tags and practices

The strength of AnQiCMS lies in its rich built-in tags, which make it easy to display various types of content:

Get global information of the website

  • System settings tag (system):Used to get the global configuration such as website name, logo, filing number, and basic URL.
    
    <title>{{% system with name="SiteName" %}}</title>
    <img src="{{% system with name="SiteLogo" %}}" alt="网站Logo" />
    
  • Contact information label (contact):Easily retrieve contact, phone, address, email, and other information from the website backend settings.
    
    电话:{{% contact with name="Cellphone" %}}
    地址:{{% contact with name="Address" %}}
    
  • Universal TDK tag (tdk):It is crucial for SEO, it can automatically generate or obtain the settings according to the current page type (home page, article, category, etc.)title/keywordsanddescription.
    
    <meta name="description" content="{{% tdk with name="Description" %}}">
    

Build navigation and page structure

  • Navigation list tags (navList):Used to generate the top, bottom, or side navigation menu of a website. It can handle multi-level navigation and highlight the selected item based on the current page state.
    
    <ul>
    {% navList navs %}
        {% for item in navs %}
            <li class="{% if item.IsCurrent %}active{% endif %}">
                <a href="{{ item.Link }}">{{ item.Title }}</a>
            </li>
        {% endfor %}
    {% endnavList %}
    </ul>
    
  • Breadcrumbs navigation tag (breadcrumb):Automatically generate the hierarchical path from the current page to the homepage, enhancing user experience.
    
    {% breadcrumb crumbs with index="首页" %}
        {% for item in crumbs %}
            <span><a href="{{ item.Link }}">{{ item.Name }}</a></span>
        {% endfor %}
    {% endbreadcrumb %}
    

Display content categories and single pages

  • Category list label (categoryList):Get the category list under the content model of articles, products, etc., which supports filtering by model ID and parent category ID.
    
    {% categoryList categories with moduleId="1" parentId="0" %}
        {% for item in categories %}
            <h3><a href="{{ item.Link }}">{{ item.Title }}</a></h3>
        {% endfor %}
    {% endcategoryList %}
    
  • Category detail tag (categoryDetail):Get detailed information of a specific category, such as category title, description, thumbnail, etc.
    
    <h1>{{% categoryDetail with name="Title" %}}</h1>
    <div>{{% categoryDetail with name="Description" %}}</div>
    
  • Single page list (pageList) and details (pageDetail):Similar category tags, but used to display independent single-page content such as 'About Us', 'Contact Us', etc.

Core content: articles and product display

This is the core of website content operation, AnQiCMS provides powerful tags to handle the list and details of articles and products.

  • Document list tag (archiveList):This is one of the most commonly used tags, used to retrieve lists of articles or products. It supports various filtering and sorting methods:
    • By model ID and category ID: moduleId="1" categoryId="1"
    • Sorting: order="id desc"(Latest release),order="views desc"(Most viewed)
    • List type: type="list"(Normal list),type="page"(Paged list),type="related"(Related articles)
    • Quantity limit: limit="10"
    • Search keywords: q="关键词"
    {% archiveList archives with type="page" moduleId="1" limit="10" %}
        {% for item in archives %}
            <a href="{{ item.Link }}">
                <h3>{{ item.Title }}</h3>
                <p>{{ item.Description }}</p>
                <span>发布日期:{{ stampToDate(item.CreatedTime, "2006-01-02") }}</span>
            </a>
        {% endfor %}
    {% endarchiveList %}
    
  • Document details tag (archiveDetail):Used to display the detailed content of a single article or product. You can directly output the title, text, view count, and custom fields of the document.
    
    <h1>{{% archiveDetail with name="Title" %}}</h1>
    <div class="content">{{% archiveDetail with name="Content" lazy="data-src" %}|safe}}</div>
    <span>浏览量:{{% archiveDetail with name="Views" %}}</span>
    
  • Previous document (prevArchive) And the next document (nextArchive):Convenient for users to switch content while reading details.

Related articles

How can you use the scheduled publishing feature to precisely control the display time of content on the website?

In the daily work of content operation, the timing of content release is often closely related to the communication effect, user reach, and overall activity of the website.It is particularly important to control the display time of content on the website accurately, whether it is to cater to the peak of user activity, cooperate with marketing activities, or simply to maintain the regularity of website updates.Anqi CMS knows this point, therefore it has specially designed an efficient and convenient scheduling publishing function, making content going online more strategic and automated.### Precisely control the timing of content going live Want to take advantage of the scheduling publishing feature of Anqi CMS, the process is actually very intuitive

2025-11-08

How to control the display permission of specific content based on user groups and VIP levels?

In website operation, providing differentiated content experience for different user groups is an important strategy to enhance user stickiness and achieve content monetization.The user group and VIP system of AnQiCMS (AnQiCMS) is the key function that helps us achieve this goal.By flexibly setting the display permissions of content, you can easily create paid content, exclusive member articles, or tiered reading services, making your website content more valuable.### Deeply understand the user group and VIP system of AnQi CMS AnQi CMS built-in user group management and VIP system

2025-11-08

How does AnQiCMS protect the copyright of displayed content through anti-crawling and watermark functions?

In the digital age, the value of original content is self-evident, but the problem of content theft and plagiarism is becoming increasingly prominent.For website owners and enterprises who work hard in creation, how to effectively protect their digital assets has become an important issue.AnQiCMS (AnQiCMS) fully understands this pain point, and from the very beginning of the system design, it has placed content copyright protection at the core position, especially through its built-in anti-crawling interference code and image watermark features, providing users with a comprehensive and efficient content protection strategy.### Content collection prevention: Protect the originality of text thoughts Imagine, the carefully written article you have written

2025-11-08

How does the static setting affect the display structure of the website URL?

Have you noticed that some website URLs are clear and easy to understand, with the content of the page being evident at a glance, while others are filled with complex question marks and numbers, leaving one puzzled?This difference largely comes from the 'pseudo-static' setting of the website.In Anqi CMS, URL rewriting is a very practical and powerful feature that can profoundly affect the display structure of your website's URL, thereby having an important impact on the website's SEO and user experience.What is pseudo-static and why is it important?First, let's understand what pseudo static is. Usually

2025-11-08

How to configure website adaptive display on different devices (PC, mobile)?

In the era of the prevalent mobile Internet, whether a website can provide a smooth and beautiful browsing experience on different devices (whether it is a large screen PC or a small mobile phone) has become a key factor in measuring whether a website is successful or not.AnQiCMS knows this pain point and provides flexible and powerful adaptive display configuration capabilities to help your website easily navigate the multi-screen world. AnQiCMS divides the adaptive display methods of websites into three main modes, you can choose the most suitable solution according to your business needs and technical preferences.

2025-11-08

How does the new content model feature enhance the flexibility of content display?

In today's rapidly changing digital world, the content carried by websites is no longer just simple articles and product introductions.From an exciting online event, a detailed customer case, to a professional team introduction, and a complex service process, each type of content has its unique attributes and presentation methods.If your content management system (CMS) still only uses the universal templates of "article" or "product" to publish all information, it will undoubtedly bring many limitations to content creation and display.

2025-11-08

How to display the Tag tag list of articles or products in AnQiCMS?

In Anqi CMS, flexibly displaying the Tag tag list of articles or products is a key link to improving the organization of website content and user experience.By carefully designed tags, it can not only help visitors quickly find the content they are interested in, but also effectively optimize search engine crawling and improve the website's SEO performance.Today, let's delve into how to fully utilize the Tag feature in AnQiCMS to revitalize the content of your website.### Understanding AnQiCMS Tag Tags In the AnQiCMS management background

2025-11-08

Does the background template editing function support real-time preview of content display effects?

AnQi CMS is favored by many operators for its efficient and flexible features in the field of website content management.When we talk about the visual presentation and user experience of a website, the customization capabilities of the template are undoubtedly the core.Among them, the real-time preview of the background template editing function and the display effect of the content is a focus for many users. ### The template editing capability of AnQi CMS: powerful and flexible AnQi CMS provides users with powerful and flexible backend template editing functions.The system uses a template engine syntax similar to Django, which is understandable for users familiar with front-end development or template languages

2025-11-08