During the process of building a website with AnQiCMS, we often encounter such a need: we hope that a specific category list page, or a unique article detail page, has a layout and style that is different from the global unified default template.AnQiCMS as a content management system focusing on flexibility and customizability, provides a very convenient and powerful solution in this aspect, allowing us to easily achieve this fine-grained template call.

Implement the call to custom templates for category or article detail pages, AnQiCMS mainly provides two main methods: one is to follow specific naming conventions, the system will automatically recognize and apply; the other is to manually specify the template file to be used during backend content editing.Both methods have their advantages and can be flexibly chosen according to the actual scenario.

1. Achieve automatic template matching through naming conventions

AnQiCMS knows the importance of efficiency, therefore it introduces a set of intelligent template naming conventions.The system will automatically invoke without additional configuration when accessing the corresponding page, as long as you create the template file according to these rules.This method is especially suitable for pages where you know you will use a specific template for a long time, one-time configuration, and done forever.

In particular:

  1. For article or product detail pages:If you want an article with ID10or a product detail page under the model ID20to have an independent template, you can specify the corresponding model (for example:)文章模型The table name may bearticle,产品模型The table name may beproductCreate a template file named with ID in the template folder. For example:

    • For ID:10For the article:article/10.html.
    • For ID:20The product of 【en】: Create in your theme template directory.product/20.html. When users visit the detail pages of these articles or products, the system will prioritize and apply these specific ID template files.
  2. For category list pages:If you wish to display the category list page of an article with ID5or the category list page of a product with ID8to have a unique display, you can create a template folder under the corresponding model.list-分类IDNamed template file. For example:

    • For ID:5Article category: Create in your theme template directoryarticle/list-5.html.
    • For ID:8Product category: Create in your theme template directoryproduct/list-8.html[en] This way, when users visit the list pages of these categories, the system will automatically load these customized templates.
  3. For single-page:Single page (such as "About Us12, you can create it in the theme template directory.page/12.htmlThe system will directly call this template when accessing this single page.

These convention-named template files should be placed in the corresponding subdirectory under the root directory of your current theme template (for example:)/template/你的主题目录/article/10.html), to ensure that the system can identify them correctly.

Two, specify the template file manually in the background

In addition to automatic matching, AnQiCMS also provides a flexible option to specify templates directly for individual articles, categories, or single pages in the backend interface.This approach gives us finer control, especially suitable for those who do not want to rely on ID naming, or need to use more descriptive template names.

  1. Specify the template for the article or product detail page:When you need to set a separate template for a specific article or product, you can enter the AnQiCMS backend, navigate to 'Content Management' under 'Document Management', find and edit the corresponding article or product.In the "Other Parametersdownload.htmlorspecial_product_detail.htmlMake sure to ensure this custom template file (for exampledownload.html) Already exists in the root directory of your current theme template. If the file does not exist, the page will not open normally.

  2. Specify a template for the category list page:If you want to customize a template for a category list page, you can go to the 'Content Management' under the 'Document Category' in the background and edit the corresponding category.In the "Other Parameters", you will find a "Classification Template" field.special_category_list.html.It is worth mentioning that the category template also provides an option for 'Apply to subcategories'.Tick this box, all sub-categories under this category will automatically inherit and use the custom template you specify, without the need to set each one individually, greatly improving management efficiency.

  3. Specify a template for the single page:For single-page template customization, it is also handled in the background.Enter the 'Page Resources' under 'Page Management', and edit the corresponding single page.In the page editing details, you will see a 'Single Page Template' field.page/about.html.

Whether through convention naming or manual specification behind the scenes, all custom template files must be.htmlsuffix, and located in the theme you are currently using/template/你的主题目录/Below. The styles, JS scripts, images, and other static resources used in the template are usually stored in/public/static/directory, and referenced by{% system with name="TemplateUrl" %}tags to ensure the correct loading of resources.

Through these flexible template calling mechanisms, AnQiCMS allows us to tailor unique display methods to every corner of the website according to various needs such as content marketing, SEO optimization, and user experience, truly realizing the freedom and personalization of content presentation.


Common Questions (FAQ)

Q1: When customizing the file naming of template files, will there be a conflict if multiple articles or category IDs point to the same template file?A1: No. The system will match according to priority. If you set a specific article ID10createdarticle/10.html, and also manually specified the article in the backgroundcustom_article.htmlThen, the manually specified template will be called first. Naming conventions are used to facilitate batch operations or scenarios that do not require backend intervention, while manual specification by the backend provides more fine-grained control.

Q2: I have specified a custom template on the backend, but the front-end page has not changed. What could be the reason?The most common reason is that the custom template file itself does not exist or the path is incorrect.Please carefully check if the template file you specified exists in your subject template directory, and ensure that the filename and path are exactly consistent with those filled in the background.In addition, if the page has a cache, it may be necessary to clear the AnQiCMS system cache to see the updated effect.

Q3: If I have customized a category template and enabled the 'Apply to subcategories' option, but I want a specific subcategory to have its own unique template that overrides it, is that possible?A3: Yes, it can be overwritten.Although setting 'Apply to subcategories' in the parent category will make the subcategories inherit the template by default, you can still edit any subcategory individually and specify a more specific template file in its 'Category template' field.The independent settings of subcategories will override the inherited settings of parent categories, achieving more flexible hierarchical control.