How to customize the display template for specific documents, categories, or single pages?

Calendar 👁️ 89

When using AnQiCMS to manage website content, we often need to assign unique display styles and functional layouts to specific content types or unique pages.This type of requirement is very common in content operation, for example, a product introduction page may need richer image display and parameter comparison, while a news article focuses on the text reading experience;Or it is a single page "About Us" on the website, which needs to show a unique corporate culture.AnQi CMS provides flexible template customization features, allowing you to easily meet these personalized display needs.

The template mechanism of Anqi CMS is designed to be very intuitive and easy to understand. It adopts the syntax of Django template engine, with.htmlAs a suffix for template files, and all template files are stored in the root directory of the website/templatein the folder. This centralized management method facilitates the organization and maintenance of templates.

To set a custom template for specific content, usually three main aspects can be considered: for individual documents (articles or products), for the content list page of the entire category, and for a specific single page.

(article/product) custom template application

In the operation, you may encounter situations where you need to design a unique layout for a specific article or product detail page.For example, you have published an important event notification and hope it has a special promotional style, or a star product needs a more attractive display interface.

To achieve this personalization, you can set it when editing the corresponding document in the Anqi CMS backend.In the interface for "Publishing documents" or editing articles/products details, there is usually a section called "Other parameters" or similar, which contains an input box named "Document template."}Here, you just need to enter the custom template filename (such asactivity_details.htmlorstar_product.htmlAfter saving, the document will be rendered using the template you specified.

In addition, Anqi CMS supports a more intelligent template recognition mechanism. If you name the template file as{模型table}/{文档id}.htmlformat (for example, if your article model table is namedarticle, the document ID is123The template file can be namedarticle/123.html), the system can also automatically recognize and apply. This means that you can prepare a template for a specific document directly according to the content ID, without manually specifying it in the background.

It is worth mentioning that you can also set a document template for all documents under the "Document Classification" settings.This means that if all products under a certain product category need a unified special display template, you only need to configure it once under that category, and all new and existing products will automatically continue to use that template, greatly enhancing management efficiency.

Category page custom template settings

The layout and functionality of the category page (such as news list, product list) may also need to be adjusted according to the content.For example, you have a 'Case Display' category that you want to be displayed in a grid waterfall style, while the 'Industry Information' category should be displayed in a traditional list style.

For this kind of requirement, you can find the corresponding category in the "Document Category" management on the Anqi CMS backend and enter the editing interface.In the "Other Parameters" area, there will also be a "Classification Template" field.Here, you can specify a custom template file to render the content list under the category (for examplecase_list.html)

Anqi CMS will default to using{分类模型}/list.htmlsuch naming conventions to render the category list page. But if you have more fine-grained control requirements, you can create something like{模型table}/list-{分类id}.htmlSuch a template file, the system will also prioritize recognition and use. For example, if you have oneproductModel, the category ID is456You can createproduct/list-456.htmlFile to customize the list page for the specific product category.

In the category template settings, there is also a very practical option called 'Apply to Subcategories'.If this option is checked, the custom template settings of the current category will be automatically inherited by all its subcategories, which can effectively reduce the amount of repetitive configuration work when building a website with a hierarchical structure.

Single-page custom template usage

In addition to documents and categories, single pages on the website (such as "Contact Us", "About Us") often require unique page designs to carry specific information or interactive functions.

SafeCMS also provides independent template customization capabilities for single-page applications.In the background under "Page Resources" and "Page Management", when editing or adding a single page, you will see the settings item for "Single Page Template".Here, you can specify the custom template file to be used for this single page, for exampleabout_us.html.

Similar to documents and categories, the system also has default naming conventions to identify single-page templates:page/detail.htmlIt is the default template for single pages. If you want an ID to be789Single page has a dedicated template that can be createdpage/789.htmlFile. A more flexible approach is to create a descriptive-named template for a specific single page, such as for the "About Us" pagepage/about.htmlThen associate it with the corresponding single page in the background.

The placement and naming conventions of template files.

No matter whether you are customizing document, category, or single page template, all of them..htmlTemplate files should be stored in/templatethe root directory of the template theme folder you are currently using. For example, if you are usingdefaulta theme, the custom template is placed in/template/default/directory.

When naming a custom template, you can determine the filename according to your habits and needs. Just make sure to correctly associate it in the corresponding settings in the background. For example, you can name a document asspecial_report.html, can be named as a categoryproduct_gallery.html, can be named as a single pagefaq_page.html. The system provides two file organization modes: folder organization mode (such asarchive/detail.html) and flattened file organization mode (such asarchive_detail.html),You can choose one according to the scale of the project and your personal preference.But no matter which pattern it is, the key is that the template file name you fill in the background needs to match the actual file path and name exactly.

Important reminder:

  1. File existence:Make sure the custom template file specified in the background is actually present in the corresponding template directory on the server.If the file does not exist or the path is incorrect, the page will not load properly.
  2. Encoding format:Template files should use UTF-8 encoding to avoid Chinese garbled characters.
  3. Adapt for mobile:If your website needs special adaptation for mobile devices, you can create it in the template theme directorymobile/Subdirectory, and place the exclusive mobile template files with the same structure as the PC end.
  4. Save and clean up the cache:After changing the template file or backend settings, please save and clear the system cache of Anqicms in time to ensure that the changes take effect immediately.

By using these flexible custom template functions provided by Anqi CMS, you can easily achieve personalized display of website content, meet various complex operational needs, and thus create a more attractive and feature-rich website.


Frequently Asked Questions (FAQ)

Q1: I customized the template file and made backend settings, but when I accessed the page, I found that the template did not take effect, and the page still displayed the default style. Why is that?A1: This situation usually has several possible causes.First, please check that the template file name you have filled in the background is exactly the same as the actual file name (including case) and that the file indeed exists in the template theme directory you are currently using.Secondly, Anqi CMS has a caching mechanism. After modifying the template or backend settings, you need to manually clear the system cache in the "Update Cache" function on the backend to make the changes take effect.Finally, check the server file permissions to ensure the system can read your template file.

Q2: How can I obtain the data of the current document, category, or single page in a custom template to display it in the template?A2: The Anqi CMS provides rich template tags for retrieving and displaying data. For example, in the custom template of the document detail page, you can use{% archiveDetail with name="Title" %}to retrieve the document title, or{{archive.Content|safe}}To display the document content. For category details, there are{% categoryDetail with name="Title" %}. For a single page, there is{% pageDetail with name="Title" %}etc. These tags automatically identify the context data of the current page, and you can alsoidortokenThe parameter specifies the data to be retrieved.

Q3: If I specify a custom template for a category, will all documents under this category also use this template?A3: Will not. The "category template" specified for the category is used to render the list page of the category (for example, displaying the list page of all articles under the category).If you want all the 'documents' in the category to use a specific detail page template, you need to find another field in the category settings, usually named 'document template', where you enter the name of the detail page template you want to use for all documents in the category.

Related articles

How to choose the appropriate template type for the AnQiCMS website to optimize cross-device display effects?

It is crucial to ensure that the website displays well on different devices when building and operating a modern website.A website that provides a smooth experience on all screen sizes has become a norm as users access websites through various devices such as smartphones, tablets, and computers, not only improving user satisfaction but also helping to effectively disseminate content and optimize search engine rankings.AnQiCMS (AnQiCMS) offers various template types to meet this need, helping us flexibly deal with cross-device display challenges.

2025-11-08

How to ensure UTF-8 encoding of template files to avoid Chinese content from displaying garbled?

When using AnQi CMS to build and manage a website, you may encounter situations where Chinese content is displayed as garbled characters. This is usually not a problem with the system itself, but rather due to inconsistent encoding of template files.By ensuring that the template file uses UTF-8 encoding, you can completely resolve this problem, allowing the website content to be presented clearly and accurately to visitors. AnQi CMS was designed with the pursuit of efficiency, flexibility, and ease of use. It excels in supporting multiple languages and SEO optimization, and proper coding is the foundation for leveraging these advantages.

2025-11-08

How to control the conditional display and loop display of AnQiCMS page content with Django template syntax?

In the flexible and powerful AnQiCMS content management system, the dynamic display of page content cannot do without the support of template syntax.Mastering conditional display and loop display of these two core functions can help us present data more efficiently and accurately on the website front-end.AnQiCMS uses a template syntax similar to Django, making it easy to create content templates that are both familiar and easy to use.

2025-11-08

How do AnQiCMS template file suffix and directory structure affect the display of front-end pages?

During the process of building a website with AnQiCMS, the template file suffix and directory structure play a crucial role, as they directly determine how the content of your website is presented to visitors.Understanding these rules can help us customize the appearance of the website more efficiently and achieve personalized content display.First, AnQiCMS uses the `.html` extension as the unified suffix for template files.This means that all template files we edit and create will end with .html.This convention not only makes the file type clear at a glance

2025-11-08

How to display common website elements, such as headers and footers, uniformly through template fragments (partial)?

When managing website content in Anqi CMS, you may find that many pages have similar structures, such as top navigation, footer copyright information, sidebar, or metadata tags, etc.If you have to write this code repeatedly for each page, it is not only inefficient, but also once you need to modify it, you have to search and update it page by page, which takes time and is prone to errors.Fortunately, Anqi CMS provides a very elegant solution - **template fragments (Partial)**, which helps us manage these common elements efficiently and uniformly.###

2025-11-08

How to correctly call and display the system configuration information in AnQiCMS templates?

Manage website content in AnQiCMS, it is not just to publish articles and products, but also includes the basic information, contact information, SEO metadata and other system-level configurations of the website.These configuration information is usually required to be displayed correctly on all pages of the website, such as displaying the website logo and name in the page header, displaying the copyright and filing number in the footer, or displaying the company's phone number and address on the contact us page.Properly and flexibly invoking these system configurations is the key to ensuring consistency, ease of maintenance, and SEO-friendliness of the website.AnQiCMS uses syntax similar to the Django template engine

2025-11-08

How to dynamically display the contact information of the website in AnQiCMS templates?

In website operation, clearly and accurately displaying the website's contact information is a key link in building trust with users and providing support.A contact method that is easy to find and keep updated, which can not only improve the user experience but also help users find you quickly when necessary.AnQiCMS as an efficient content management system provides a very flexible and intuitive way for you to dynamically display and manage this important information in website templates.

2025-11-08

How to set and display search engine friendly TDK (Title, Description, Keywords) for AnQiCMS pages?

Search engine optimization (SEO) is an indispensable part of website operation, and the Title (title), Description (description), and Keywords (keywords) - abbreviated as TDK - of the website page are the foundation of SEO.They are the first step for search engines to understand page content and a key factor for users to decide whether to click on search results.

2025-11-08