How can I customize a template for a specific category or page to control the display style?

Calendar 👁️ 74

When operating a website, we often encounter such situations: different types of content, even articles in the same category or different 'About Us' pages on the same website, all hope to have a unique display style to better attract readers and convey information.AnQiCMS (AnQiCMS) fully understands this need and therefore provides a very flexible template customization mechanism, allowing us to easily customize the display style for specific categories or pages.

The Anqi CMS template system is based on the Django template engine syntax in Go language, which means that as long as you have a basic understanding of front-end development, you can quickly get started.It allows us to create or modify template files and associate them with specific content on the backend, thereby achieving fine-grained style control.

1. Understand the storage and naming conventions of template files

Before starting customization, we first need to know the location of the template files and some basic naming conventions. The template files of Anqi CMS are stored uniformly in/templateUnder the directory. Each template will have its own independent folder, such asdefault. In this folder, you can place all the related content for this template..htmlFiles, while styles (CSS), JavaScript scripts, and images, etc., static resources will be stored in/public/static/Directory.

The Anqi CMS template system is very intelligent, it supports various ways to identify and apply templates:

  1. Universal default template:For articles, product lists, detail pages, single pages, etc., there is a universal default template. For example,{模型table}/detail.htmlUsed for the detail pages of all articles or products,{模型table}/list.htmlFor all article or product list pages, whilepage/detail.htmlIt is the default template for all single pages. When no special template is specified, the system will automatically call these general templates.

  2. The convention template for binding ID or alias:If you want a specific document, category, or single page to have a unique style, you can name the template file using its ID or URL alias.

    • ForDocument detail pageYou can create{模型table}/{文档ID}.htmlThe template file, for examplearticle/123.htmlThe system will automatically apply this template when accessing the article with ID 123.
    • ForCategory list pageCan create{模型table}/list-{分类ID}.htmlThe template format, for examplearticle/list-5.htmlWhen accessing the article category list with ID 5, this template will take effect.
    • Forsingle pageCan createpage/{单页面ID}.htmlThe template format, for examplepage/7.htmlThese conventions for naming make it unnecessary for you to make additional settings in the background, as the system can automatically recognize and apply them.
  3. Flexible templates with custom naming:In addition to the aforementioned agreements, AnQi CMS also provides the most flexible method - you can freely name the template files and then specify the use of this template in the corresponding content editing interface in the background. For example, you can create a template nameddownload-page.htmlThe template is specifically used for a special download page.

No matter which method you choose, make sure your template file uses UTF-8 encoding to avoid page garbled text. In addition, if your website needs to adapt to mobile devices, you can create a folder in the template directory.mobileSubdirectory, and copy the same template structure in it, the system will automatically call it on the mobile phonemobileThe template under the directory.

Second, associate the custom template in the background

After creating the template file, the next critical step is to inform the Anqi CMS which content should use which template.This process is very intuitive, usually you can find the corresponding options in the content editing interface.

  1. Customize templates for articles or products:When you publish or edit a document (article or product) in the "Content ManagementHere, you can enter the filename of the template you wish to use for the document.special_news.htmlA template, specifically used to display an important news article, just fill in herespecial_news.htmlJust do it.

  2. Custom template for categories:In the "Content Management" "Document Category" page, when editing a category, there is also a "Category Template" field in the "Other Parameters". Here you fill in the template filename (for exampleproduct_list_promo.htmlIt can make all the list pages of the category have a unique style.It is particularly noteworthy that there is also an option for "whether to apply to subcategories". If you check it, all subcategories (and their document lists) under this category will inherit the use of this custom template, which is very convenient for achieving a unified style for a product line or service series.

  3. Custom template for single page:In the "Page Resources" under "Page Managementabout_us_fancy.htmlTemplate, fill in here.

When you specify a custom template in the background, Anqicms will prioritize and use the file you specified when rendering the corresponding page.If the file does not exist, the page will not be able to open normally, so please make sure that the path and name of the template file are correct.

Section 3: Tips for writing within the template.

In your custom template file, you can use tag syntax similar to Django to control content display. For example,{{变量名}}Used for output data, and{% 标签 %}which is used for logical control, such as,{% if 条件 %}to make judgments,{% for item in 列表 %}Perform a loop.

It is strongly recommended to make use of templates to improve maintainability and reusability.{% include "片段.html" %}and{% extends "基础模板.html" %}These tags.includeYou can include commonly used code snippets such as headers, footers, sidebars, etc. in your template to avoid repetition;extendsIt allows you to create a basic page skeleton (including common HTML structure, style references, etc.), and then let other pages inherit this skeleton, only rewriting the customized blocks.This way, changing the common part only requires changing one place, greatly improving efficiency.

By this means, the template customization function of Anqi CMS is like customizing a set of exclusive clothing for every corner of the website, allowing content to present in a proper scene with **posture.In order to enhance user experience, strengthen brand image, or optimize the SEO display of specific content, this flexible control capability can bring tangible convenience and value to the operation of your website.


Frequently Asked Questions (FAQ)

  1. Q: Where should I place my custom template file in the website directory?A: You should place the custom template file in/template/您的模板目录/. For example, if your template directory isdefaultThen it can be placed in/template/default/. If you are customizing a template for a specific document, category, or single page, you can also follow the agreement (such asarticle/123.htmlor

Related articles

Does the background template editing function support real-time preview of content display effects?

AnQi CMS is favored by many operators for its efficient and flexible features in the field of website content management.When we talk about the visual presentation and user experience of a website, the customization capabilities of the template are undoubtedly the core.Among them, the real-time preview of the background template editing function and the display effect of the content is a focus for many users. ### The template editing capability of AnQi CMS: powerful and flexible AnQi CMS provides users with powerful and flexible backend template editing functions.The system uses a template engine syntax similar to Django, which is understandable for users familiar with front-end development or template languages

2025-11-08

How to display the Tag tag list of articles or products in AnQiCMS?

In Anqi CMS, flexibly displaying the Tag tag list of articles or products is a key link to improving the organization of website content and user experience.By carefully designed tags, it can not only help visitors quickly find the content they are interested in, but also effectively optimize search engine crawling and improve the website's SEO performance.Today, let's delve into how to fully utilize the Tag feature in AnQiCMS to revitalize the content of your website.### Understanding AnQiCMS Tag Tags In the AnQiCMS management background

2025-11-08

How does the new content model feature enhance the flexibility of content display?

In today's rapidly changing digital world, the content carried by websites is no longer just simple articles and product introductions.From an exciting online event, a detailed customer case, to a professional team introduction, and a complex service process, each type of content has its unique attributes and presentation methods.If your content management system (CMS) still only uses the universal templates of "article" or "product" to publish all information, it will undoubtedly bring many limitations to content creation and display.

2025-11-08

How to configure website adaptive display on different devices (PC, mobile)?

In the era of the prevalent mobile Internet, whether a website can provide a smooth and beautiful browsing experience on different devices (whether it is a large screen PC or a small mobile phone) has become a key factor in measuring whether a website is successful or not.AnQiCMS knows this pain point and provides flexible and powerful adaptive display configuration capabilities to help your website easily navigate the multi-screen world. AnQiCMS divides the adaptive display methods of websites into three main modes, you can choose the most suitable solution according to your business needs and technical preferences.

2025-11-08

How to configure different content display templates for mobile and PC separately?

In website operation, providing a good browsing experience for different devices is crucial.AnQi CMS knows this, it provides a flexible template mechanism, allowing you to easily configure different content display templates for mobile and PC terminals, thereby meeting user needs and improving website performance.Below, let's take a detailed look at how to achieve this goal in Anqi CMS.### Understanding AnQi CMS Template Mode AnQi CMS provides three main website modes to meet the needs of content display on mobile and PC platforms in different scenarios: 1.

2025-11-08

What file extension should AnQiCMS template files use to ensure correct display?

When using AnQiCMS for website construction and content management, ensuring that the template files are displayed correctly is the foundation for the normal operation of the website.This is where, the naming convention of template files, especially the file extension, plays a crucial role. The template files of Anqi CMS have a clear and unified file extension requirement, which is to use **.html** as the file extension of the template files.These files are usually organized in the `/template` folder under the root directory of the website.Choose `.html`

2025-11-08

How to display variables in AnQiCMS templates?

In AnQiCMS templates, how to effectively display variable data is a core skill that every website operator and template creator needs to master.AnQiCMS uses a syntax similar to the Django template engine, making data calls and display both intuitive and flexible.This article will delve into various ways to display variables in AnQiCMS templates, helping you accurately present dynamic information such as backend configuration data and article content on the website front-end.

2025-11-08

How to use conditional judgment and loop control to dynamically adjust the display of content?

In Anqi CMS, we often encounter scenarios where we need to display different information based on specific conditions or repeat a series of contents.At this time, by flexibly using conditional judgment and loop control, the website content can become more vivid and intelligent.The AnQi CMS template feature provides powerful syntax support similar to the Django template engine, through these tags, we can easily achieve dynamic content adjustment without writing complex background code. ### Conditional judgment: Make the content 'speak to people' Conditional judgment is the basis for dynamic content display.Imagine

2025-11-08