How to use Django template engine to dynamically present content in AnQiCMS?

AnQiCMS as an efficient and customizable content management system, one of its core advantages lies in its powerful content display capabilities.This is largely due to the system's support for the Django template engine syntax.This means that content operators and website developers can flexibly obtain, process, and display various types of website data on the frontend without writing complex backend code.

Core Mechanism: Understanding the Application of Django Template Engine in AnQiCMS

In AnQiCMS, the Django template engine provides a solid foundation for dynamic content display. Its operation is intuitive and easy to learn, mainly achieved through two basic syntax structures:

  1. Variable output({{ 变量名 }}):This is the most direct way to present dynamic content. You can refer to data passed from the system or backend by using double curly braces in the template. For example,{{ archive.Title }}The title of the article can be directly output,{{ system.SiteName }}The website name will be displayed. This method gives static HTML templates life, allowing them to display personalized information based on different data content.

  2. Logical control ({% 标签 %}):In addition to simple data display, more complex content organization and interaction requires logical control tags.These tags allow you to perform conditional judgments, loop traversal, and include other template files in the template.

    • Conditional judgment ({% if 条件 %} ... {% elif 其他条件 %} ... {% else %} ... {% endif %}):The display of website content often needs to be switched according to specific conditions.For example, determine if the user is logged in, if a field has a value, or if certain content is recommended, etc., to display different content blocks or styles.
    • Loop traversal ({% for 变量 in 列表 %} ... {% empty %} ... {% endfor %}):List data (such as article list, product list, category list) is the most common content form on a website. ThroughforLoop, you can easily iterate and display each item in the list.emptyThe introduction of tags can elegantly handle the case of an empty list, providing friendly prompt information.

Benefiting from the high concurrency features of AnQiCMS based on the Go language, as well as its concise and efficient system architecture, the template engine performs excellently in parsing and rendering these dynamic contents, ensuring the website's access speed and stability.

AnQiCMS provides core dynamic content tags

AnQiCMS is built-in with rich template tags, which greatly simplify the operations of various data acquisition and display, allowing you to focus on front-end design and content organization.

  • Website global information and navigation construction:

    • {% system ... %}Tags can retrieve the website name, Logo, filing number, copyright information, and other basic configurations, making it convenient for you to call them at various places on the page.
    • {% contact ... %}Tags are used to obtain contact information set in the background, such as phone, email, address, etc.
    • {% tdk ... %}Tags are an important tool for SEO, they can dynamically retrieve the current page's Title, Keywords, and Description, and support site name attachment, delimiter customization, etc.
    • {% navList ... %}Labels can help you build flexible website navigation menus, supporting multi-level navigation and custom navigation categories, making the website structure clear and easy to understand.
    • {% breadcrumb ... %}Tags are used to generate breadcrumb navigation, enhancing user experience and website accessibility.
  • Acquisition and display of core content (articles, products, pages):

    • {% archiveList ... %}is one of the most commonly used tags, used to retrieve a list of articles or products.It supports filtering by categories, models, recommended attributes, keywords, and other conditions, and provides pagination functionality.You can easily create news lists, product showcase pages, and related article recommendations.
    • {% archiveDetail ... %}Tags are used to obtain detailed information about a single article or product, including the title, content, images, views, and even custom field content.
    • {% pageList ... %}and{% pageDetail ... %}Tags focus on the management and display of single-page content, such as independent pages like 'About Us' and 'Contact Us'.
    • {% prevArchive ... %}and{% nextArchive ... %}The label can automatically retrieve the previous and next articles of the current article, commonly used in the bottom navigation of article detail pages.
    • {% archiveParams ... %}Tags are specifically used to retrieve custom parameters set in the article model. This is very useful for displaying personalized product attributes or additional article information.
    • {% archiveFilters ... %}It is a powerful filtering tool, especially suitable for building custom field filtering functions based on content models on list pages, such as filtering by house type, product size, and so on.
  • Category and Tag System Construction:.

    • {% categoryList ... %}Tags are used to obtain the category list of articles or products, support multi-level nested calls, and easily build a hierarchical classification structure.
    • {% categoryDetail ... %}Can obtain detailed information of a specific category, such as category name, description, Banner image, etc.
    • {% tagList ... %}Used to get the tag list related to articles or the hot tags of the entire site.
    • {% tagDataList ... %}Tags can be used to retrieve a list of related articles based on a specific tag.
  • User interaction and feature expansion:

    • {% commentList ... %}Used to display the comment list of articles, supporting pagination and multi-level comments.
    • {% guestbook ... %}Tags can render the message form configured in the background, making it convenient for users to submit information.
    • {% linkList ... %}Tags are used to display friend links.
    • {% pagination ... %}Tags andarchiveListortagDataListCombined use can easily generate page navigation.

In addition to these powerful tags, AnQiCMS's template engine also supports multipleFiltersfor example|safeto avoid HTML content from being escaped,|dateorstampToDateUsed for formatting time,|truncatecharsUsed for truncating strings and adding ellipses, as well as|add/|replaceetc., for data processing. These filters make it extremely convenient to process data twice in the template.

Application scenario: Flexibility of dynamic content display

The Django template engine of AnQiCMS not only provides basic data display, but also supports a variety of complex dynamic content needs through its flexible design:

  • Personalized content model and custom fields:With the help of灵活的内容模型Features, you can define unique fields for different types of content (such as articles, products, job positions). ByarchiveParamsTags, the data of these custom fields can be dynamically presented in the template, achieving highly customized content pages.
  • Content reuse under multi-site management:AnQiCMS supports多站点管理Many tags in the template supportsiteIdParameters, which means you can dynamically call data from another site in a template of a site, realizing content sharing or cross-site display.
  • Responsive design and multi-end adaptation:AnQiCMS allows for different网站模式(such as adaptive, code adaptation, PC+Mobile independent sites) set different template directories.Combine with Django template engine, you can provide optimized dynamic content layout for mobile and PC, ensuring a good user experience on any device.
  • Dynamic TDK and pseudo-static in SEO optimization:Combine伪静态规则andtdkTags, you can dynamically generate SEO **best practices**-compliant URLs and meta information based on the content of articles, categories, or single pages, greatly enhancing search engine friendliness.

Through the powerful Django template engine of AnQiCMS, dynamic content display is no longer a technical challenge.Whether it is to build a complex corporate website, a rich media platform, or manage multiple independent sites, AnQiCMS provides a set of intuitive and efficient solutions for you to easily manage the dynamic presentation of website content.


Common Questions (FAQ)

  1. How to get specific article or category data other than the current page in the template?You can usearchiveDetailorcategoryDetailtags, and throughidSpecify the ID of the target article or category. For example,{% archiveDetail with name="Title" id="10" %}Get the title of the article with ID 10. Similarly,archiveListandcategoryListLabels are supportedcategoryIdandmoduleIdparameters help you accurately filter the data you need.

  2. Can I include another template file within a template? Will it affect the scope of variables?Of course. AnQiCMS supports it.{% include "文件路径" %}Tags can be used to include other template files, which is very useful for achieving template modularization and code reuse, such as separating headers, footers, or sidebars. By default, includeThe template introduced will inherit all variables of the current template. If you want to pass specific variables or limit the scope, you can usewithandonlyparameter, such as{% include "partial/header.html" with title="我的标题" only %}.

  3. How to create filtering conditions for some custom fields of website content (such as product color, size, etc.)?AnQiCMS provides{% archiveFilters ... %}Tags are specifically used for this purpose. First, you need to define these fields as filterable in the content model on the backend. Then, in the frontend template, usearchiveFiltersLink to generate these filtering conditions. When the user clicks on these links, it combinesarchiveListtags, the system will dynamically display a list of matching content based on the selected custom field values.