How to implement custom template file calling for category or article detail pages in AnQiCMS?

Calendar 👁️ 51

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.

Related articles

How to judge if a variable is empty in the template and display a default value?

During the presentation of web content, we often encounter such situations: a variable may be empty due to data loss, user failure to fill in, or other reasons.If you directly output these empty variables in the template, it may result in blank spaces on the page, affecting the appearance, or even cause layout errors, and may even expose unnecessary debugging information.It is particularly important to set a suitable default value for these variables that may be empty to ensure the completeness of website content display and the smoothness of user experience.The AnqiCMS uses a template engine syntax similar to Django

2025-11-07

How does AnQiCMS control the special display style of articles by setting the Flag attribute?

In Anqi CMS, the Flag attribute of the article is a very practical feature, which allows us to tag articles with special "labels" to display them uniquely on the website front-end.This mechanism greatly enhances the flexibility and diversity of content display, allowing website operators to easily control the display style and position of articles based on the importance, characteristics, or promotion needs of the content.What is the article Flag attribute? In simple terms, the Flag attribute is like a special "mark" that is attached to the article, it is not a category of the article

2025-11-07

How to automatically wrap long text for display in AnQiCMS templates?

During the operation of the AnQiCMS website, we often encounter scenarios where we need to display a large amount of text content, such as the main content of article detail pages, detailed descriptions of product introductions, or long introductions on category pages.These long texts, if not handled properly, may cause page layout to be disordered and affect the user's reading experience.Fortunately, AnQiCMS's powerful template engine provides various flexible ways to manage and display these long texts, including automatic line breaks and content truncation.AnQiCMS's template system has adopted the syntax of Django template engine, allowing us to use double curly braces

2025-11-07

How to automatically filter or process external links in AnQiCMS article content?

In daily website content operation, we often encounter situations where external links need to be cited in articles.These external links are handled well, they can enrich the content and provide references, but if not managed properly, they may also affect the SEO performance or user experience of the website.AnQiCMS is a content management system that focuses on efficiency and SEO, providing practical automated solutions in this aspect, helping us better manage external links in the article content.### Core options in the background content settings The core mechanism of AnQiCMS handling external links in articles

2025-11-07

How to format numbers in AnQiCMS templates, such as retaining decimal places?

In AnQiCMS template development, formatting numbers for display, especially controlling decimal places, is a very common requirement.No matter whether you want to display the price of products, the percentage in statistical data, or other values that need to be presented accurately, AnQiCMS's powerful template engine provides flexible filters (filters) to help you achieve these goals.

2025-11-07

How to automatically add watermarks to images in article content in AnQiCMS to protect copyright?

In today's era of increasingly rich digital content, the copyright protection of original images is particularly important.Whether it is a carefully photographed product image or an illustration drawn for an article, they all embody the creator's efforts and the brand image of the website.However, the situation where pictures are downloaded and used without permission is common, which not only violates copyright but may also dilute brand influence.Luckyly, AnQiCMS provides a convenient and efficient solution that helps us automatically add watermarks to images on the website, thereby effectively protecting original content.

2025-11-07

How to remove HTML tags in AnQiCMS template and display only plain text content?

When using AnQiCMS for content creation and display, we often need to flexibly control the presentation of content on the front end.Sometimes, the article or product description may contain rich HTML tags, which are used to provide beautiful layout on the detail page.

2025-11-07

How to display the current model name or URL alias in AnQiCMS?

In website content management, we often need to make the various parts of the website adapt and display information intelligently, one common requirement being how to dynamically display the name or URL alias of the current content model on the front-end page.This is crucial for improving user experience, optimizing search engine performance, and flexible management of website structure.AnQiCMS as an enterprise-level content management system provides a very flexible and powerful template tag function, making it intuitive and efficient to achieve this goal.

2025-11-07