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 Django template engine syntax.This means that content operators and website developers can flexibly obtain, process, and display various types of data on the front-end page 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 pick up, mainly implemented 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. For example,{{ archive.Title }}You can directly output the title of the article,{{ system.SiteName }}The website name will be displayed. This way, the static HTML template comes to life instantly, able to display personalized information based on different data content.

  2. Logic 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 traversals, and introduce other template files and operations 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, judge whether the user is logged in, whether a field has a value, whether some content is recommended, etc., so as 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 where the list is empty, 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 with rich template tags, which greatly simplify various data retrieval and display operations, allowing you to focus on front-end design and content organization.

  • Website global information and navigation building:

    • {% system ... %}Tags can obtain 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 used to obtain contact information set in the background, such as phone, email, and address.
    • {% tdk ... %}Tags are an important tool for SEO, they can dynamically retrieve the Title, Keywords, and Description of the current page, and support the addition of site name and custom separators.
    • {% navList ... %}Tags can help you build a flexible website navigation menu, supporting multi-level navigation and custom navigation categories, making the website structure clear and easy to understand.
    • {% breadcrumb ... %}Tags used to generate breadcrumb navigation, enhance user experience and website accessibility.
  • Acquisition and display of core content (articles, products, pages):

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

    • {% categoryList ... %}Tags are used to obtain the classification list of articles or products, support multi-level nested calls, and easily build a tree-like classification structure.
    • {% categoryDetail ... %}Can retrieve detailed information about a specific category, such as category name, description, Banner image, etc.
    • {% tagList ... %}Used to retrieve the tag list related to the article 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 list of comments for articles, supporting pagination and multi-level comments.
    • {% guestbook ... %}Tags can render the backstage configured message form, making it convenient for users to submit information.
    • {% linkList ... %}Tags are used to display friend links.
    • {% pagination ... %}with the tag andarchiveListortagDataListCombined use can easily generate page navigation.

In addition to these powerful tags, AnQiCMS's template engine also supports a variety ofFilter (Filters)For example|safeused to prevent HTML content from being escaped,|dateorstampToDateused to format time,|truncatecharsUsed to truncate strings and add ellipses, as well as|add/|replaceand for data processing. These filters make it extremely convenient to process data twice in the template.

Actual application scenario: flexibility of dynamic content display

AnQiCMS's Django template engine 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灵活的内容模型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, realizing a highly customized content page.
  • Content reuse under multi-site management:AnQiCMS supports多站点管理Many tags support in the template.siteIdParameters, this means you can dynamically call data from another site's template on a site, to achieve content sharing or cross-site display.
  • Responsive design and multi-end adaptation:AnQiCMS allows for different网站模式(such as adaptive, code adaptation, PC+Mobile independent site) set different template directories.Combine Django template engine, you can provide optimized dynamic content layout for mobile and PC terminals, ensuring a good user experience on any device.
  • Dynamic TDK and pseudo-static in SEO optimization:Combine伪静态规则andtdkTag, you can dynamically generate a URL and meta information that complies with SEO **practices based on the content of the article, category, or single page, greatly enhancing search engine friendliness.

By using AnQiCMS's powerful Django template engine feature, dynamic content display is no longer a technical challenge.Whether it is to build a complex enterprise 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.


Frequently Asked Questions (FAQ)

  1. How to get specific article or category data other than the current page in the template?You can usearchiveDetailorcategoryDetailLabel, and throughidThe parameter specifies the ID of the target article or category. For example,{% archiveDetail with name="Title" id="10" %}Will retrieve the title of the article with ID 10. Similarly,archiveListandcategoryListTags also supportcategoryIdandmoduleIdwith parameters to help you accurately filter the required data.

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

  3. How to create filter conditions for some custom fields of website content (such as product colors, sizes, etc.)?AnQiCMS provided{% archiveFilters ... %}Labels are specifically used for this purpose. First, you need to define these fields as filterable in the content model in the background. Then, in the frontend template, usearchiveFiltersLink to generate these filter condition links. When users click on these links, combinearchiveListTags, the system will dynamically display a list of matched content based on the selected custom field value.