How to use the Django template engine of Anqi CMS to create highly customized content display pages?

Calendar 78

Today, with the increasing importance of digital content, how a website efficiently and beautifully presents its content is directly related to user experience and brand image.AnQiCMS (AnQiCMS) leverages its flexible and powerful Django template engine, providing endless possibilities for highly customized content display pages.This article will delve into how to utilize the core capability of Anqi CMS to create content display pages that meet business needs and are unique in craftsmanship.

The foundation of AnQi CMS template system

First, let's understand the working principle of AnQi CMS templates.The AnQi CMS adopts the Django template engine syntax loved by developers, making template writing both intuitive and powerful.

  • Variable output:Using double curly braces{{ 变量名 }}To display data passed from the backend, for example, displaying the article title{{ archive.Title }}.
  • Logical and control:Use single curly braces and percentages{% 标签 %}To implement complex logic such as conditional judgment, loop iteration, and introducing other templates, for example, conditional judgment{% if condition %}or loop list{% for item in list %}.

All template files are stored in the root directory/templateIn the folder. For easy management and theme switching, each independent template theme will have its own dedicated directory and include aconfig.jsonFiles are used to describe topic information. For static resources such as CSS, JavaScript, images, etc., they are placed in one place./public/static/Under the directory, it ensures clear resource management and efficient loading.

The template system of Anqi CMS also supports various organization modes, such as folder organization by function (such asindex/index.html/{模型table}/detail.html), can also be a more flattened file organization pattern (such asindex.html/{模型table}_detail.html)。It is more thoughtful that it allows us to define exclusive template files for specific document IDs, category IDs, or single page IDs, such as creating one for the "About Us" page.page/about.htmlThis provides convenience for achieving high customization.

Core customization tool: flexible and powerful template tags and filters

The powerful customization capabilities of AnQi CMS largely come from its rich built-in template tags and data filters. They are the bridge connecting backend data with frontend display.

1. Accurate content call: Various data tags

AnQi CMS provides detailed tags to obtain various content data from the website:

  • Document content tags (archiveDetail/archiveList):This is the core of the website, which can be used to display detailed information pages of articles or products, or to display content lists on the homepage or category pages.It can not only call basic fields such as document ID, title, content, thumbnail, but also flexibly read various custom fields for different content models (such as article models, product models) on the background, such as product properties such as color, size, etc.moduleId/categoryId/flagWith parameters, it can easily filter out specific content sets such as 'Hot Articles', 'Latest Products', or 'Slide Recommendations.'
  • Category page label (categoryDetail/categoryList):Used to display detailed information about categories or list the category list under a specified model. Whether it is creating hierarchical navigation or displaying subcategories under a large category, it is very proficient.
  • Single page tab (pageDetail/pageList):For independent pages such as "About Us" and "Contact Us", these tabs can conveniently retrieve page content and configuration.
  • Tab page tab (tagDetail/tagDataList):Used to display the details of a specific tag and the list of all documents associated with the tag, which helps to build a content association network.
  • Content model tag (moduleDetail):At a deeper level, you can obtain meta information of the content model through model tags, which is very useful when building highly dynamic content displays.
  • Global auxiliary tags: systemThe tag can retrieve the website name, Logo, filing number, and other global configurations;contactThe tag is used to display contact information;tdkThe tag can dynamically set the title, keywords, and description required for SEO on each page;navListThe tag is used to build multi-level website navigation;breadcrumbTags can generate clear page paths and enhance user navigation experience.

2. Logical control and data processing: structured tags and filters

In addition to content calls, the Anqi CMS template engine also provides powerful logic control capabilities:

  • Conditional judgment and loop (if/for):Use{% if 条件 %}and{% for item in 列表 %}It can easily achieve conditional display of content and iteration of list data. For example, display different content based on whether the user is logged in, or loop to display multiple product images.forLoops also supportemptyClause, displays default content when the list is empty, as well asforloop.Counteretc., convenient for implementing numbering, odd and even row styles, etc.
  • Variable definition (with/set): {% with 变量名="值" %}or{% set 变量名="值" %}It is convenient to define temporary variables in templates, avoiding repeated calculations or making the code more concise, especiallyincludevery useful when introducing public templates.
  • time formatting (stampToDate):Easily convert timestamps to easily readable date or time formats to meet display needs in different scenarios
  • Template reuse (include/extends/macro): {% extends "base.html" %}Can define the page skeleton and inherit to achieve unified global styles and layout;{% include "partial/header.html" %}Can split and reuse common modules (such as header, footer, sidebar); and{% macro %}It allows the definition of reusable code snippets (similar to functions),配合importCan be shared between different templates.

To further refine data, Anqi CMS also built-in richFilter (Filters)such as|safeUsed to safely output HTML content (such as article detail rich text);|truncatechars:100Used to truncate long text and add an ellipsis;|join:", "Used to concatenate array elements into a string;|add:10Used for simple addition of numbers;|loweror|upperUsed for text case conversion;|date:"2006-01-02"Used for date formatting;|floator|integerUsed for type conversion;|trimUsed to remove leading and trailing spaces or specified characters. These filters allow flexible and accurate processing of data before display.

Achieve highly customized paths

Understood these template features, we can then start to create highly customized content display pages.

  1. Plan the content model, enrich the data source:In the background "Content Model", create or modify models according to your business needs and add various custom fields.For example, if you want to display real estate information, you can add custom fields such as 'house type', 'area', 'price', 'location', and so on to the 'real estate model', which will become the data foundation for the front-end page.
  2. Build the page skeleton and implement modularization:UtilizeextendsTags, design a general for the website:base.htmlScaffold, define the header, footer, navigation, and other public areas, and use:{% block 名称 %}Mark the area that can be replaced.This way, all pages will share the basic layout and can flexibly fill in content in their own templates.includeLabel, extract it into an independent file and import as needed.
  3. Refined content display, creating a unique style:
    • Customization of detail pages:Utilize in article or product detail pages,archiveDetailLabels, not only can display the main content of the article (through{{ archive.Content|safe }}), and can also be used in loops{% archiveParams params %}Dynamically display all custom fields, such as a detailed technical parameter list for a product. For the image carousel, you can use{{ archive.Images }}to get the image group andfordisplay in a loop.
    • Customization of the list page:applyarchiveListTags, combined withmoduleIdandcategoryIdParameters, can easily build 'news list', 'latest products', and so on. If your content model defines filterable parameters (such as 'real estate model' in 'area' and 'house type'), thenarchiveFiltersThe tag will shine, it can automatically generate filtering conditions, cooperatearchiveListImplement complex content filtering function. Don't forgetpaginationTags, it can automatically generate pagination links, ensuring smooth browsing of large amounts of content.
    • Customization of the homepage and special topic pages:The home page and special theme pages often require richer content combinations. You can use multiplearchiveListTags, combined withflagParameters such asflag="c"to indicate recommendations,flag="f"to indicate slides) to display content modules in different areas.categoryListIt can also be used to build a featured classification area.
  4. Optimize user experience and SEO:
    • Page meta information:In each template's<head>section, using{% tdk with name="Title" %}/{% tdk with name="Keywords" %}/{% tdk with name="Description" %}tags, ensure that each page has accurate SEO meta information to improve search engine friendliness.
    • Navigation and Path:UsenavListBuild a clear main navigation and sidebar navigation usingbreadcrumbTags to generate breadcrumb navigation, helping users understand their current location and improve website usability.
    • URL Structure:Coordinating with the static rule configuration of the AnQi CMS backend, as well as the custom URL features for documents, categories, single pages, and tags in the template, it is possible to create URL structures that are more in line with SEO standards and user habits.
    • Responsive design:Leveraging the adaptive, code compatibility, and PC+mobile independent site features supported by Anqí CMS, responsive layouts or separate mobile-end templates (placed in the selected template type according to the selected template type)mobileDevelop under the directory) to ensure a good browsing experience on different devices.

By using the above method, you will be able to fully utilize the Django template engine of AnQi CMS, from data models to front-end display, creating a highly customized, feature-rich, and user-friendly content display page.


Frequently Asked Questions (FAQ)

Q1: How to create a new content type (such as "Real Estate Information") in Anqi CMS and display it on the front end?

A1:On the Anqi CMS backend, you can create a new content type through the 'Content Management' module's 'Content Model' feature.First, click 'Add New Model', define the model name (such as 'Real Estate'), table name, and URL alias.Then, you can add exclusive custom fields for the 'housing model', such as 'type' (drop-down selection), 'area' (numeric), 'price' (numeric), 'location' (single-line text), and so on.After creating the model, add categories for the "Property Model" in "Document Classification" and publish the "Property" content in "Document Management".

Related articles

Which website modes does AnQi CMS support to adapt to the display of content on PCs and mobile devices?

In this diverse digital age of devices, whether browsing news, shopping, or accessing services, users may visit websites through PCs, laptops, tablets, or smartphones.Therefore, whether your website content can be displayed clearly and beautifully on different screen sizes is directly related to user experience and brand image.AnQi CMS understands this core requirement and provides a variety of flexible website modes to ensure that your content is displayed in a perfect posture on any device.

2025-11-07

How does Anqi CMS provide a high-performance architecture to ensure stable display of website content under high concurrency?

In the current digital age, whether a website can stably display content under high concurrent traffic is a key indicator of whether a content management system (CMS) is excellent.For those of us who operate websites on a daily basis, focusing on user experience and the effectiveness of content marketing directly relates to brand image and business conversion.How does AnQiCMS (AnQiCMS) achieve this, still keeping the website content stable as a mountain under high concurrency?

2025-11-07

How can the timing release function of Anqi CMS accurately control the display time of articles and products?

In the daily operation of a website, the timing and rhythm of content release often play a crucial role in marketing effectiveness, user experience, and even search engine optimization.AnQiCMS (AnQiCMS) is well-versed in this, carefully designing a powerful "timed release" function for users, helping us accurately control the online time of articles and products, and realizing the automation and efficiency of content operation.

2025-11-07

How to set up the AnQi CMS user group and VIP system to display exclusive paid content?

In AnQi CMS, to achieve exclusive display of paid content, it usually requires combining its powerful user group management and VIP system functions.This not only helps your website effectively monetize content, but also provides users at different levels with a differentiated service experience.Next, we will step by step explore how to set up to make your exclusive content visible only to paid users. Understanding Core Concepts: User Groups and Content Reading Levels The core of implementing paid content in Anqi CMS lies in the concepts of "User Groups" and "Content Reading Levels".

2025-11-07

What is the organization method of the AnQi CMS template file to ensure the correct loading and display of content?

In AnQiCMS (AnQiCMS), the organization of template files is directly related to the correct loading, display efficiency, and subsequent maintenance convenience of website content.A clear and reasonable template structure that allows you to handle complex content display requirements with ease and greatly enhances team collaboration efficiency.The AnQi CMS uses Go language as the development foundation, its template engine syntax is similar to Django, which provides powerful and flexible tools for template developers.Understanding its core principles and following certain organizational standards will make your website operation twice as effective.

2025-11-07

How to reference static resources (such as CSS/JS/images) in AnQi CMS template to beautify content display?

In content operation, the aesthetics and user experience of the website are crucial, and this largely depends on the reasonable use and management of static resources (such as CSS stylesheets, JavaScript scripts, and images).For users who use AnQiCMS, mastering how to efficiently and standardizedly refer to these resources in templates is a key step to building a high-quality website.

2025-11-07

In Anqi CMS template, how are `{{variable}}` and `{% tags %}` used for displaying dynamic content and logical control?

AnQiCMS with its high efficiency and flexibility has become a good helper for content management.The presentation of website content cannot do without templates, and in the AnQiCMS template system, `{{variable}}` and `{% tag %}` are the core elements for building dynamic pages and realizing powerful functions.They each have different responsibilities, and they collaborate closely to make our website content vibrant. --- ### `{{variable}}`:The intuitive presentation of data Imagine what you want to display on the page, such as the title of an article or the name of a website.

2025-11-07

How to handle the UTF-8 encoding of Anqi CMS template to avoid garbled display of website content?

When using Anqi CMS to manage website content, you may occasionally encounter situations where乱码 appear on the page, which is usually related to the encoding settings of the template file.The AnQi CMS has specific requirements for the encoding of template files - it must use UTF-8 encoding uniformly.Understanding and properly handling this stage is the key to ensuring that the website content is displayed normally and provides a good browsing experience. Why do character codes appear乱码?

2025-11-07