How to create and manage multiple website templates for AnQiCMS and achieve differentiated display on different pages?

Calendar 👁️ 68

AnQiCMS provides high flexibility in creating and managing website templates, allowing users to easily achieve differentiated display of different pages, thereby meeting the diverse content operation needs.This is due to its simple and efficient architecture and support for a variety of template patterns.

Understanding the template mechanism of AnQiCMS

The core of AnQiCMS templates lies in the easy-to-use Django template engine syntax, which allows even users without a strong development background to customize templates relatively easily. All template files are stored in a unified location./templateUnder the directory, each independent template will have its own dedicated folder. In this folder,config.jsonFiles play a crucial role, defining the name, version, author, and most critical template type of the template.

The system supports various template types, includingAdaptive template/Code adaptation templateandPC+mobile independent templateThis means you can choose a template to fit all devices, or design two completely independent templates for the PC and mobile end, or even bind a separate domain for the mobile end.In cases where an independent mobile template is needed, simply create a folder namedmobilePlace the mobile-end related template files in the subdirectory, and the system can automatically recognize and adapt.

Create and manage custom website templates

Create a new website template, first you need to/templatecreate a new folder under the directory as your new template directory. Next, create a new folder in this new directory.config.jsonFile, fill in the basic information of the template, such as template name, package name (recommended to be consistent with the folder name, for internal system identification), version number, etc. among themtemplate_typeField (0 for adaptive, 1 for code adaptation, 2 for PC + mobile independent) andstatusThe field (0 for disabled, 1 for in use) is the key to controlling template behavior. The system defaults to only one set of templates.statusA value of 1 indicates that it is in use.

AnQiCMS provides conventions for template file naming, which greatly simplifies the template creation process. For example, the homepage is usually namedindex.htmlAnd different content model home pages (such as article list pages, product list pages) can be named{模型table}/index.htmlSimilarly, the article detail page can be named{模型table}/detail.htmlCategory list page is named{模型table}/list.htmlSingle page detail page is namedpage/detail.html. Static resources (such as CSS, JavaScript files, images, etc.) are recommended to be stored in/public/static/directories to maintain a good file organization structure.

The template enable and switch is done in AnQiCMS backend, you can easily select, enable or disable different templates in the template management interface of the backend, no manual modification is requiredconfig.jsonfile.

Implement the differentiated display of different pages

AnQiCMS provides multi-level customization capabilities in implementing the differentiated display of pages:

  1. Global general page display:Like the website homepage(index.html)Search result page(search/index.html)and various error pages(errors/404.html,errors/500.html)and others, can all be managed and displayed uniformly through preset template names.

  2. Display based on content model:AnQiCMS's flexible content model is the cornerstone of differentiated display.You can create different content models according to business needs (such as "articles", "products", "news"), and design a set of independent template structures for each model.Further, you can target in the backgroundSpecific categories/specific documentorspecific pagespecify the independent template it uses. For example, a "About Us" page, you can set the template to bepage/about.htmlTo make it have a completely unique layout and content presentation. An article for a special download page can specify its document template asdownload.html.

  3. Using template tags and logic control:Even in the same template file, you can also use the rich template tags and logic controls provided by AnQiCMS (such as{% if ... %}condition judgment and{% for ... %}Loop through) to achieve dynamic content display and layout differences. For example, usingarchiveDetailtags to obtain the details of the current article, or throughcategoryDetailto obtain the classification attributes. CombineifThe statement, you can decide the display style and structure of the content based on whether the article has a thumbnail, whether it contains specific tags, and other conditions.

  4. Differences in multi-site and multi-language:If your business needs to manage multiple brands or sub-sites, AnQiCMS's 'Multi-site Management' feature allows you to independently select a set of templates for each site, even deploying them as completely different website forms.With "multilingual support", you can also provide customized templates for different language versions of the website to ensure that the content is presented in different language environments.

Template management and maintenance

To enhance the development efficiency and maintainability of templates, AnQiCMS templates support code reuse mechanisms. For example, using{% extends 'base.html' %}Implementing template inheritance, abstracting the common structure of the website (such as header, footer) tobase.htmlwhere the child template only needs to rewrite{% block ... %}defining specific areas. At the same time, utilizing{% include "partial/header.html" %}Introduce reusable code snippets, or through{% macro ... %}Define macro functions with parameters that can effectively reduce redundant code.

AnQiCMS also has built-in backend editing template features, making it convenient for you to make lightweight template modifications and debugging. For multilingual websites, the system also supports multilingual template definitions, and it can be done through{% tr "yourLocation" %}This label implements the translation and switching of interface text.

In summary, AnQiCMS offers a powerful and flexible template creation and management solution, from global template selection to page customization, to dynamic content display and multilingual adaptation, all of which can enable you to efficiently build a website that meets the brand image and user experience.


Frequently Asked Questions (FAQ)

  1. How to change the template currently in use on the website?You can log in to the AnQiCMS backend and find the 'Website Template Management' page under the 'Template Design' menu.Here, you can see all the uploaded templates, select the template you want to enable, and click the "Enable" button to complete the switch.Please note that after switching the template, the style and layout of the website front page will change immediately.

  2. Can I use a completely different template layout for the PC and mobile ends?Yes. When you create a template, you can do so in the root directory of the template.config.jsonfile willtemplate_typeSet to 2 (PC + standalone mobile mode). Next, create a folder namedmobileThe subdirectory, and put the template files designed for mobile in it.The system will automatically load the corresponding template based on the type of device being accessed.You can even bind a separate domain for the mobile end in the "background settings".

  3. Do I have a special "Contact Us" page that needs a layout completely different from other single pages, can AnQiCMS achieve this?Of course you can. When creating or editing the 'Contact Us' page, there is an option for 'Single Page Template' in the backend editing interface.You can enter the name of the template file you have designed specifically for this special page, for examplecontact.html(Make sure the file exists in your current template directory'spage/folder, such astemplate/your_template/page/contact.html). This specific single page will be displayed using the unique template you specified, achieving a completely personalized layout.

Related articles

How to customize the front-end page layout of the AnQiCMS website to meet brand requirements?

Customizing the front-end page layout in AnQiCMS is a key step to creating a brand image and providing a unique user experience.This system relies on its flexible template engine, rich functional modules, and user-friendly design concept to provide powerful customization capabilities for website operators. ### AnQiCMS Foundation for Layout Customization: Template System Overview AnQiCMS uses a template engine similar to Django syntax, which means the visual presentation of the website is separated from the core business logic.All elements of the front-end page, from overall structure to content display

2025-11-07

Does the `addslashes` filter in the future version of AnQiCMS add more configurable escape options?

AnQiCMS provides flexible and powerful features in content management and template rendering. The future development direction and configurability of details in data processing, such as the `addslashes` filter, are issues of concern for many users. Currently in the AnQiCMS template system, the `addslashes` filter is a basic string processing feature, which adds a backslash before the specified predefined characters.According to the document, these characters mainly include single quotes (`'`)

2025-11-07

How does the `addslashes` filter coordinate with AnQiCMS's 'Content Security Management, Sensitive Word Filtering' feature?

In website operation, content security and sensitive word filtering are indispensable foundations to ensure the healthy and compliant operation of the website.AnQiCMS (AnQiCMS) is well-versed in this field, providing users with comprehensive and powerful content management functions, with 'Content Security Management' and 'Sensitive Word Filtering' being the core highlights.Behind this, some seemingly minor but crucial tools, such as the `addslashes` filter, are silently playing their unique role, working in synergy to build a security barrier for the website.### Dual protection of website content safety

2025-11-07

When outputting the filename of a user-uploaded file in the template, can the `addslashes` filter enhance security?

In website content operations, file upload and display are common requirements.When we need to output the file name uploaded by the user in the Anqi CMS template, a natural question arises: Can using the `addslashes` filter effectively enhance security?This content will delve into the role of the `addslashes` filter and the kind of security it can provide in the context of filename output.First, let's understand the `addslashes` filter itself.

2025-11-07

How to implement code adaptation or independent site mode display for the mobile and PC templates of AnQiCMS?

When using AnQiCMS to build a website, we often encounter a core issue: how to ensure the website has an excellent browsing experience on different devices, whether it's a wide PC screen or a small mobile screen?AnQiCMS provides us with flexible and diverse solutions, mainly focusing on adaptive, code adaptation, and independent sites for PC and mobile, which help us achieve this goal.First, let's take a look at each of these patterns and their implementation in AnQiCMS.### 1. Adaptive Mode (Responsive

2025-11-07

How to efficiently refer to external static resources (CSS, JS, images) in AnQiCMS template files?

When building a website with AnQiCMS, the design of the template and the effective reference to static resources are key to ensuring website performance and ease of maintenance.The loading speed and user experience of a website largely depend on whether its CSS styles, JavaScript scripts, and image resources can be efficiently transmitted to visitors.AnQiCMS provides a clear and practical mechanism for handling these external static resources, allowing us to focus more on content creation rather than cumbersome technical details

2025-11-07

How to ensure that the encoding format of AnQiCMS template files is correct and avoid display of garbled characters on the page?

In website operation, the display of乱码is undoubtedly one of the most annoying problems, it not only severely affects user experience, but may also damage your brand image.For friends using AnQiCMS, encountering such problems, the encoding format of the template file is often the primary object to investigate.Ensure that your AnQiCMS template files use the correct encoding format, which is the basis for ensuring the normal display of website content and providing a smooth user experience.

2025-11-07

How does AnQiCMS utilize modular design for template secondary development and personalized display adjustment?

AnQiCMS is an enterprise-level content management system based on the Go language, and its powerful modular design is one of its core advantages.This design concept is not only reflected in the system architecture, but also deeply affects the flexibility of secondary template development and personalized display adjustment, allowing website operators to easily create unique and highly customizable content platforms. **The Foundation of AnQiCMS Modular Design** AnQiCMS can achieve efficient and flexible template customization, which is inseparable from its underlying modular architecture.

2025-11-07