During the process of building a website with AnQiCMS, we often encounter the need that a specific category list page or a unique article detail page should have a layout and style that is different from the global unified default template, rather than following the default template.AnQiCMS as a content management system focusing on flexibility and customization provides a very convenient and powerful solution in this regard, allowing us to easily implement this refined template call.

Implement custom template calls 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;Another one is to manually specify the template file to be used while editing the content in the background.Both of these methods have their advantages, and they can be flexibly chosen according to the actual scenario.

1. Automatic matching of templates through naming conventions

AnQiCMS understands the importance of efficiency and therefore introduces a set of intelligent template naming conventions.If you follow these rules to create the template file, the system will automatically call it without additional configuration when accessing the corresponding page.This approach is especially suitable for pages where you know you will be using a specific template for a long time, one-time configuration, once and for all.

In particular:

  1. For article or product detail pages:If you wish to display an article with ID10or a product detail page under a product model with ID20has its own template, you can specify the corresponding model (for example:文章模型The table name might bearticle,产品模型The table name might beproductCreate a template file named with ID in the template folder. For example:

    • For ID:10article: Create it in your theme template directory.article/10.html.
    • For ID:20The product: Create it in your theme template directoryproduct/20.html. When users visit the detail pages of these articles or products, the system will prioritize searching for and applying these specific ID template files.
  2. For category list pages:If you wish to display the list page of articles with a certain ID of5or the list page of product categories with a certain ID of8with a unique display, you can create a template folder under the corresponding model template.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. This way, when users visit the list pages of these categories, the system will automatically load these customized templates.
  3. For a single page: Single-page templates (such as "About Us", "Contact Us") customization is also convenient. If you have a single-page with an ID of12you can create it in the theme template directory.page/12.html. The system will directly call this template when accessing this single page.

These conventionally 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 correctly identify.

Chapter 2: Manually specify the template file in the background

In addition to automatic matching, AnQiCMS also provides flexible options to directly specify templates for individual articles, categories, or single pages in the background 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 a template for the article or product detail page:When you need to set a separate template for a specific article or product, you can go to the AnQiCMS backend, navigate to 'Content Management' under 'Document Management', find and edit the corresponding article or product.In the "Other Parameters" section of the editing page, there will be a "Document Template" field.You can enter the name of the template file you have pre-created here, for exampledownload.htmlOrspecial_product_detail.html. Make sure to ensure that this custom template file (for exampledownload.htmlThe file 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 the template for the category list page:If you want to customize the 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 "category template" field.Enter the name of the template file you want, for examplespecial_category_list.htmlIt is worth mentioning that the category template also provides an option for 'whether to apply to subcategories'.Check this option, all subcategories under this category will automatically inherit and use the custom template you specify, without the need to set them one by one, greatly improving management efficiency.

  3. Specify a template for the single page:For single-page template customization, it is also operated in the background.Go to 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.You can enter a custom template filename here, for example, specify for the "About Us" pagepage/about.html.

Whether through agreed naming or manually specified in the background, all custom template files must be.htmlsuffix, and located in the theme you are currently using/template/你的主题目录/The styles, JS scripts, and images as static resources used in the template are usually stored in/public/static/In the catalog and pass through{% system with name="TemplateUrl" %}tags to refer to the path, ensuring the correct loading of resources.

By these flexible template invocation mechanisms, AnQiCMS enables us to tailor unique display methods for every corner of the website according to various needs of content marketing, SEO optimization, and user experience, truly realizing the freedom and personalization of content presentation.


Frequently Asked Questions (FAQ)

Q1: When customizing template file naming, if multiple article or category IDs point to the same template file, will a conflict occur?A1: Will not. The system will match according to priority. If you specify an article ID for10createdarticle/10.html, and also manually specified the article in the backgroundcustom_article.htmlThen the manually specified template will be called first. Naming conventions are for the convenience of batch operations or scenarios without backend intervention, while manual specification by the backend provides more fine-grained control.

Q2: Why did the custom template I specified in the background not change on the front page?A2: The most common reason is that the custom template file does not exist or the path is incorrect.Please check whether the specified template file exists in the theme template directory and whether the file name and path are exactly consistent with those filled in the background.In addition, if the page has a cache, you may need to clear the AnQiCMS system cache to see the update 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 can override, is that possible?A3: Yes, you can override. Although the 'Apply to child categories' setting of the parent category will make the child categories inherit the template by default, you can still edit any child category separately and specify a more specific template file in its 'Category Template' field.The independent settings of the subcategory will override the inherited settings of the parent category, achieving more flexible hierarchical control.