In content management, the diversity of presentation methods is the key to improving user experience and brand image.A website that can present different design styles and information layouts according to different types of content will undoubtedly make it more attractive and professional.AnQiCMS understands this need and provides flexible and powerful template configuration capabilities, allowing us to customize exclusive display templates for different categories and even individual documents.

Next, we will delve into how to configure this feature in AnQiCMS, making your website content shine with unique style.


Understanding the template system of AnQiCMS

In AnQiCMS, template files are the foundation for building the appearance and content layout of a website. They are usually stored with.htmlsuffix and stored in/templateThe directory where you have selected the theme folder. AnQiCMS's template engine syntax is similar to Django, using double curly braces{{变量}}to output data, using single curly braces followed by a percent sign{% 标签 %}Control the logic, such as conditional judgments and loops.

AnQiCMS has a 'convention over configuration' principle in template processing.This means that if you create template files following a specific naming convention, the system can automatically recognize and apply them without any additional settings in the background.For example, for the list page or detail page of a certain content model, the system has a default template path convention.But when we need to implement personalized display for specific categories or documents, we need to break these conventions and manually configure.


Configure exclusive list page templates for different categories

Imagine that your website has two main categories: "news center" and "product showcase".News centerBy customizing the category template, you can easily achieve such differentiation.

1. Prepare your custom template file.

First, you need to create the corresponding template file in the current theme template directory. For example, if you want to create a unique list page for the 'Download Resources' category with ID 5, you can consider the following naming methods:

  • Conventional naming:If the "Download Resources" category belongs to the "Article Model" (model table namearchive), you can create a name calledarchive/list-5.htmlTemplate file. AnQiCMS will try to load this file first when accessing the category list.
  • Custom naming:You can also create a more descriptive filename, such asarticle/download_list.htmlThis method is more flexible, but it requires manual specification in the background.

Whichever method you choose, please make sure that your template file has been uploaded to your AnQiCMS theme folder, for example/template/您的主题名/article/download_list.html.

2. Specify the template for categories in the backend

After the template file is ready, the next step is to apply it to the corresponding category.

  1. Log in to the AnQiCMS backend management interface.
  2. Navigate toContent Managementand then clickDocument Category.
  3. Find the category you want to apply a custom template to (such as “Download Resources”), click the button next toEditbutton.
  4. Scroll down to other parameters in the category editing page.Section.
  5. Incategory templateEnter the name of the template file you just created. If you used a custom name, such asarticle/download_list.htmljust fill inarticle/download_list.html. If you follow the conventional naming convention and want the system to use the file, you can also leave it blank to let the system automatically match; but for clarity, it is also fine to fill it in.
  6. Special reminder:On this page, you will also see oneApply to subcategoryThe option.If this option is checked, all subcategories under the current category (if any) will inherit and use the custom list template you set here, saving the trouble of setting it separately for each subcategory.
  7. ClickConfirmSave changes.

Configure a dedicated detail page template for a specific document

In addition to the category list page, sometimes we also need to provide unique detail displays for certain special documents (such as a detailed product introduction page, a software download page, or an event registration page).

1. Prepare your custom template file.

Similar to the category list page, you need to create a template file for the document detail page in the current theme template directory. For example, if you want to create a dedicated template for a special article, you can name itarticle/special_document_detail.html.

Make sure the file is uploaded to your AnQiCMS theme folder, for example/template/您的主题名/article/special_document_detail.html.

2. Specify the document template in the background

After completing the template file creation, you can assign the template to a specific document using the following steps:

  1. Log in to the AnQiCMS backend management interface.
  2. Navigate toContent Managementand then clickPublish document(For new documents) orDocument Management(For editing existing documents).
  3. On the document edit/publish page, scroll down to.the foldable box.
  4. InDocument TemplateIn the field, enter the custom template filename you have prepared for this document, for examplearticle/special_document_detail.html.
  5. ClickConfirmorPublishSave the document.

In this way, when the user accesses this specific document, AnQiCMS will load and use the custom template you specified, rather than the default detail page template of the category or model.


Combine content model with the use of custom fields

One of AnQiCMS's core advantages is its flexibilityContent modelFunction.Different content models (such as article models, product models) can have independent field settings, and even within the same content model, fields can be further refined through categories.

  • Article modelBelow, the "news" category may only require "title" and "content"; while the "technical article" category may need additional fields such as "author", "publishing platform", etc. custom fields.
  • Product modelUnder the "Electronics

When you customize templates for different categories or documents, these custom fields become particularly important. In custom templates, you can make use of template tags provided by AnQiCMS, such as{% archiveDetail with name="自定义字段名" %}or{% archiveParams params %}To retrieve and display this specific data. This means that your template design can directly focus on these unique fields to achieve highly customized information display.


Practical suggestions and precautions

  • Planning comes first:Before starting to customize the template, it is recommended to clarify the layout and information elements required for different categories or documents, which will help design a more reasonable and reusable template structure.
  • Modular design:Fully utilize the AnQiCMS template'sextends(Template inheritance) andinclude(Introducing code snippet) tag. Extracting common elements such as header, footer, sidebar, etc. can not only reduce duplicate code but also improve maintenance efficiency.
  • Path and naming:Make sure the template filename you enter matches the actual file path and name exactly. The path should be relative to the root directory of your current topic.
  • Test verification:After you configure or modify the template, be sure to clear the AnQiCMS background'sUpdate Cacheand test the access on multiple browsers and devices in the front end to ensure the display effect meets expectations.
  • Version control:If you do a lot of template customization, it is recommended to perform version control on the template files to track modifications and rollbacks.

Through the above configuration, your AnQiCMS website will be able to provide more accurate and personalized display for different types of content, greatly enriching the user experience and bringing more possibilities to website operation.


Frequently Asked Questions (FAQ)

1. Why is my custom template file already uploaded but not found in the "Category Template" or "Document Template" dropdown list in the background?AnQiCMS's 'Category Template' or 'Document Template' field is typically filled in manually, rather than by dropdown selection. You need to ensure that the complete relative path (such asarticle/download_list.htmlEnter into the corresponding text box. Additionally, please confirm that the template file has been correctly uploaded to the current theme being used./templateIt is spelled correctly in the directory.

2. Why do all the document detail pages under the category I have set a custom template still display the default template?The category template mainly controls the display of the *list page* of the category.If you want the *document detail page* under the category to use a custom template, you need to set the 'document template' field additionally on the category editing page, or specify the detail template for each document separately.The document template set in the category will be applied to all documents in the category (if the document itself has not set a specific template).

How to get the current category or current document data in a custom template?In AnQiCMS templates, you can use built-in template tags to retrieve data. For example, to get the title of the current document, you can use{% archiveDetail with name="Title" %}; To get the name of the current category, you can use{% categoryDetail with name="Title" %}. If you have added custom fields in the document content model, you can use{% archiveDetail with name="您的自定义字段名" %}Get its value.