How to use Django template engine syntax to efficiently display various dynamic content in AnQiCMS?

Calendar 100

Managing website content in Anqi CMS, you will find that its built-in Django template engine syntax is an extremely powerful and flexible tool, which can help you efficiently convert background data into vivid and dynamic content on the frontend page.Master this grammar, and you will not only be able to display basic text and images, but also build complex, interactive dynamic pages, bringing vitality to your website.

The template syntax design of AnQi CMS is very intuitive, it borrows the characteristics of the Django template engine and integrates the concise and efficient Go language. You will mainly encounter two core elements: those used to output variables.{{ 双花括号 }}And used for controlling logic{% 单花括号加百分号 %}Understanding both of these is the first step to efficiently using Anqi CMS templates

Flexible display of website basic information

Firstly, we start with the most basic dynamic information on the website. Anqi CMS provides convenient tags to retrieve global configuration and contact information:

  • Website global settingsDo you want to display the website name, Logo, filing number, or copyright information at any location on the website?systemTags can be easily implemented. For example, to display the website name in the page title, you can write it like this:<title>{% system with name="SiteName" %}</title>. The image address of the website logo is:<img src="{% system with name="SiteLogo" %}" alt="网站Logo" />.
  • Contact Information:Display the company's contact phone number, address, email, and even WhatsApp or Facebook links,contactTags can be useful. For example, to display contact phone number:电话:{% contact with name="Cellphone" %}.
  • Page TDK: The title (Title), keywords (Keywords), and description (Description) are crucial for the SEO optimization of each page,tdkTags can be dynamically generated. For example, setting the page's<title>Tags:<title>{% tdk with name="Title" siteName=true %}</title>.siteName=truewill also automatically include the website name suffix you set in the background.

These tags allow you to avoid hardcoding, with changes made in the background, the front-end updates immediately, greatly enhancing operational efficiency.

The core of dynamic content presentation: articles, products, and custom data

The core value of AnQi CMS lies in its flexible content model. Whether it's articles, products, or any custom content type you define, it can be easily displayed through template syntax.

  • List display:

    • To display the latest article list,archiveListLabel combinationforLoop is your powerful assistant. For example, get the latest 10 articles under a specified category:
      
      {% archiveList archives with type="list" categoryId="1" limit="10" %}
          {% for item in archives %}
          <li>
              <a href="{{item.Link}}">{{item.Title}}</a>
              <p>{{item.Description}}</p>
              <span>发布时间:{{stampToDate(item.CreatedTime, "2006-01-02")}}</span>
          </li>
          {% endfor %}
      {% endarchiveList %}
      
      HerearchivesIs the variable name you defined,itemis the object of the current article in each loop. You can accessitem.Link/item.Titlein this way to access various properties of the article.stampToDateIt is a practical filter that can format timestamps into readable dates.
    • Similarly,categoryListCan list categories,pageListList single pages,tagListList tags. They all follow a similar{% for item in collection %}cyclical pattern.
  • Display on detail page:

    • When the user clicks on an article in the list to enter the detail page,archiveDetailThe tags will automatically retrieve and display detailed content based on the article ID of the current page. To display the article title, simply<h1>{% archiveDetail with name="Title" %}</h1>. Article content usually needs special processing because it may contain HTML tags, at which point you should use|safea filter to ensure that HTML is parsed correctly and not displayed as plain text:
      
      <div>
          {%- archiveDetail articleContent with name="Content" %}
          {{articleContent|safe}}
      </div>
      
    • categoryDetailandpageDetailTags are also retrieved in a similar manner to categories and single-page details.
    • Navigation between partsIn the article detail page,prevArchiveandnextArchiveTags can conveniently generate links to the previous and next articles, enhancing the user's browsing experience.
    • Related documents:archiveListLabel collaborationtype="related"Parameters can intelligently display other articles related to the current article for you, which is very beneficial for SEO and user retention.
  • Custom fields and filtering:

    • AnQi CMS allows you to add custom fields to content models. If you add fields such as "size", "color", and so on to the product model,archiveParamsTags can help you dynamically retrieve and display these custom parameters.
    • For more advanced requirements, such as filtering content based on multiple custom parameters,archiveFiltersTags can dynamically generate filtering conditions on the list page,配合archiveListoftype="page"patterns, which can build powerful filtering functions, such as the 'area-type-price' filtering on real estate websites.

Optimize website structure and user experience

  • Navigation menu:navListTags are a powerful tool for building multi-level navigation menus. You can flexibly display the top, side, or bottom navigation of the website according to the navigation categories set in the background. By nestingforLoop, easily implement the dropdown menu effect.
  • Breadcrumbs navigation:breadcrumbTags can automatically generate the hierarchical path of the current page, helping users understand their position in the website and improve navigation clarity.
  • Pagination featureWhen the content list is long,paginationTags can intelligently generate pagination links, control the number of page numbers displayed, ensuring page loading speed and user-friendliness.

Enhance the reusability and maintainability of templates.

The reusability of templates is the key to efficient development. Anqi CMS provides several powerful mechanisms:

  • includeTag: Extract the common parts such as headers, footers, sidebars into independent template fragments, and then reference them where needed to avoid repeated code. You can even use{% include "partial/header.html" %}in the places where it is needed, to avoid duplicate code. You can even usewithParameters pass specific variables to these segments.
  • extendsTag: is used for template inheritance, you can create a basic layout (for example)base.html), defining the page skeleton and replaceable elements.blockArea. Then other pages only need{% extends 'base.html' %}and rewrite accordinglyblock, you can quickly build a page with a consistent style.
  • macroTag: If some code blocks need to be used frequently and require parameters,macroTags are like functions in templates. Defined once, called multiple times, making the code more modular and readable.
  • withwithsetTagThese two tags allow you to define temporary variables within the template, used to store calculation results or simplify complex expressions, making the template logic clearer.

Deep Data Processing: The Magic of Filters

Filters are the 'data processors' in the template, through the pipeline symbol|Apply to

Related articles

Where should the AnQiCMS template files be stored, and what file extensions are supported?

AnQiCMS is designed very clearly and flexibly in template file management, aiming to allow users to customize the appearance and functions of the website efficiently.If you are using AnQiCMS to build or maintain a website, understanding the location of template files and supported suffixes is the foundation for front-end development and customization.

2025-11-07

How to customize templates in AnQiCMS to change the overall visual style and layout of the website?

In this era that emphasizes brand and user experience, the visual style and layout of a website is the key to its successful operation.AnQiCMS (AnQiCMS) understands this point and therefore provides a highly flexible template customization feature, allowing users without a strong development background to create websites that meet their unique needs with a personalized touch.If you are considering changing the overall style of the website or want to design a dedicated layout for specific content, it will be very helpful to understand how to customize templates in AnQiCMS.

2025-11-07

How to manage custom fields in the content model of AnQiCMS and call them to display on the front-end page?

AnQi CMS is an efficient and customizable enterprise-level content management system, one of its core highlights is the 'flexible content model'.This feature greatly expands the management boundaries of website content, allowing us to create various and unique content structures according to actual business needs.Among these, custom fields (or custom parameters) play a crucial role, allowing our website content to go beyond traditional article titles, body, and summaries, and carry more personalized information, ultimately displaying flexibly on the front-end page.

2025-11-07

How to configure Docker reverse proxy to display multiple independent websites for AnQiCMS multi-site feature?

AnQiCMS (AnQiCMS) is favored by many website operators for its efficient and flexible content management capabilities.Especially its powerful multi-site management feature, combined with Docker containerization technology and reverse proxy, allows you to easily set up and manage multiple independent websites on the same server, greatly enhancing operational efficiency and reducing maintenance costs. ### Discover the charm of multiple sites Imagine that you may have several different brands, aimed at different audiences, or serving different regions, but their content update and management processes are roughly the same.

2025-11-07

How to use `if-else` conditional tags to control the display logic of content in AnQiCMS templates?

In AnQiCMS templates, make good use of the `if-else` conditional judgment tag to make content display more intelligent In website content operation, we often need to display different content or styles according to different conditions.For example, when the article list is empty, display 'No content', when an article is in the recommended state, add a 'HOT' mark, or add a special style to the first item in the loop.

2025-11-07

How to use the `for` loop tag to iterate and display list data in AnQiCMS template?

In AnQiCMS templates, dynamically displaying list data is one of the core operations for building rich website content.Whether it is displaying the latest articles, hot products, category lists, or any custom content collection, the `for` loop tag is your helpful assistant.It allows you to easily traverse data and customize the display of each item according to your needs.Understanding the basics of the `for` loop tag The `for` loop tag is a control structure in the AnQiCMS template engine used for iterating over collection data.

2025-11-07

How does AnQiCMS support the switching of multiple templates, as well as how to specify an independent template for a specific page or content type?

## The flexible aspects of AnQiCMS: How to handle multi-template switching and personalized page design A flexible template mechanism is crucial for a content management system to maintain competitiveness and adapt to diverse operational needs.AnQiCMS is an efficient enterprise-level content management system that has demonstrated excellent capabilities in this regard. It not only supports multi-template switching at the whole-site level but also provides detailed features for specifying independent templates for specific pages or content types. This is undoubtedly a powerful tool for websites that need to carry out refined content operations. Firstly

2025-11-07

How to retrieve and display the title, detailed content, summary, and recommended attributes of an article (document)?

In Anqi CMS, whether it is to display the detailed content of a single article or to preview multiple articles on the list page, flexibly obtaining and displaying the title, detailed content, introduction, and recommended attributes of the article is the foundation of website operation.The design of Anqi CMS makes this process intuitive and efficient, we mainly achieve it through template tags and variable calls.First, understand the template system of Anqi CMS is crucial.

2025-11-07