How can I implement a custom template name so that the system can automatically recognize and apply it?

Calendar 👁️ 56

As a senior security CMS website operator, I know the importance of flexible template customization for website content display and user experience.Our company's simple and efficient architecture of AnQi CMS provides us with great freedom to manage and display content.How to implement a custom template name so that the system can intelligently recognize and apply it is the key to improving operational efficiency and meeting personalized display requirements.

Anqi CMS template mechanism overview

AnQi CMS uses a syntax similar to the Django template engine, the template files are usually named with.htmlwith suffix, and stored uniformly in/templateUnder the directory. This mechanism allows us to highly customize the appearance and layout of the website.The system supports adaptive, code adaptation, and various template types such as PC+mobile independent sites to meet the needs of different terminal access.It is crucial for template creators to understand the file organization conventions and naming rules.

The organization mode of the template files follows the default conventions

AnQi CMS provides two template file organization modes: folder organization mode and flattened file organization mode.No matter which mode is adopted, the system supports a series of default custom template names.This means that as long as we create files in the template directory that comply with these naming conventions, the system can automatically identify and apply them to the corresponding content types without any additional configuration in the background.

For example, for the document detail page, the system will automatically search for{模型table}/{文档id}.htmla formatted template file. If the model table name isarticle, the document ID is10, then the system will attempt to loadarticle/10.html. Similarly, the document list page will search for{模型table}/list-{分类id}.htmlwhile a single page will searchpage/{单页面id}.htmlThese predefined naming rules provide a quick way to implement personalized content display, such as creating a unique layout for a specific article ID or category ID.

Specify a custom template name via the backend

In addition to the default automatic recognition conventions of the system, Anqi CMS also provides the function to specify custom template files for specific content (such as documents, categories, single pages) in the background.This is a more flexible customization method, allowing us to use any legally valid template filename and associate it with specific website content.

For example, if we need to design a unique template for the "About Us" page, we can first create a named template in the template design packagepage/about.htmlThe template file. Then, edit the single page "About Us" in the "Page Management" backend, and fill in the "Single Page Template" field.about.html. The system will automatically search and apply based on the specified information when loading this single page.page/about.htmlThis custom template.

Similarly, in the "Add Document" or "Edit Document" interface, we can find the "Document Template" field under "Other Parameters" and fill in examples such asdownload.htmlSpecify the document download template for this document. For document classification, there is also a 'Classification Template' field on the 'Document Classification' editing page, which can specify suchproduct-list.htmlAs the list template for this category. It is noteworthy that the category template also supports the option of whether to apply it to the child categories, allowing us to apply the custom template in bulk to all child categories below.

Ensure the correct application of the custom template

When using a custom template name, there are several key points to keep in mind.Firstly, all custom template files must indeed exist in the currently enabled template design package.If the specified template file does not exist, the system will not be able to load it correctly, which may cause the page to display errors or revert to the default template.The template name filled in the background should only contain the filename (such asabout.htmlordownload.html), rather than the full path. The system will automatically find the corresponding location in the template directory based on the content type.

Finally, to maintain the clarity and maintainability of the template code, it is recommended to use descriptive names when customizing template names and to follow certain naming conventions. For example, to use for a special category under the product model,product/list-special-offers.htmlSuch a name helps team members quickly understand its purpose.

The flexibility of Anqi CMS in customizing templates, whether through the automatic recognition of system default naming conventions or through manual specification of specific templates in the background, provides website operators with powerful tools to create unique content displays.


Frequently Asked Questions (FAQ)

1. I have specified a custom template for a document in the background (for examplemy_special_article.html), while the system also has a template that matches the automatic recognition rules (for examplearticle/detail-10.htmlWhich one will the system use first?

In most cases, the custom template explicitly specified in the "Document Template" field in the background has higher priority. This means that even if there are template files that meet the automatic recognition rules, the system will prioritize the manual configuration you have made in the background.my_special_article.htmlThis design ensures that you can have the most refined control over individual content items.

2. If I specify a custom template for a category in the background and check the 'Apply to child categories' option, will all subcategories under this category use this template?

Yes, if the option 'Apply to child categories' is checked, the custom category template will be applied to the current category and all its direct and indirect subcategories unless a subcategory has specified another custom template in its own settings.The independent settings of the subcategory will override the inherited settings of the parent category, providing flexible hierarchical control.

3. I have set a custom template name in the background, but when I access the page, it shows blank or errors, what is the reason for this?

The most common reason is that the custom template file you specified in the background does not exist in the actual template design package, or there is an error in the filename or path. Please check the following points:

  • Make sure the template file has been uploaded correctly to/templatethe directory containing the template design package you are currently using.
  • Confirm that the naming of the template file matches the name you have configured in the background (including case).
  • Ensure the file is in the correct subdirectory based on content type (for example, single-page templates should be inpage/the directory, document detail templates may be in{模型table}/in the directory).
  • Check if the template file itself contains syntax errors, these errors may also cause the page to render incorrectly.

Related articles

Where should the mobile template files be stored in a specific subdirectory?

As a senior security CMS website operation personnel, I fully understand the core position of content in user experience, and providing optimized content display for different devices is the key to retaining users.When it comes to the mobile template management of AnQi CMS, specifying the storage location of the template files is crucial for efficient content publishing and maintenance.In AnQi CMS, in order to adapt to the display of mobile devices, the system provides a specific mechanism to manage the template files for the mobile end.

2025-11-06

How to design a mobile template for independent mobile sites or code adaptation mode?

As a senior content operator specializing in AnQiCMS, I am well aware that in today's mobile internet era, providing users with an excellent mobile experience is the cornerstone of website success.Anqi CMS, with its flexible architecture, provides us with a variety of solutions to meet the challenges of mobile devices.Today, I will elaborate on how to design high-quality mobile templates for independent mobile sites or code adaptation mode in Anqi CMS.

2025-11-06

What types of template modes does Anqi CMS support?

As a website operator who deeply understands the operation of AnQiCMS (AnQiCMS) and has a profound understanding of content operation, I am very happy to give you a detailed explanation of the template mode supported by AnQiCMS.In AnQiCMS design philosophy, flexibility and adaptability are among its core advantages, which naturally also manifest in its powerful template system.AnQiCMS knows that different websites and operational strategies have diverse needs for front-end display.

2025-11-06

What encoding format should the template file be saved in to avoid page garbled characters?

Hello!As an experienced CMS website operation person, I know that every detail in content publishing and website maintenance may affect user experience.The page garbled characters are one of the common and annoying problems, which are directly related to the correct presentation of content.According to the Anqi CMS documentation, there is a clear and simple solution to this problem.

2025-11-06

What are the naming conventions to follow for a specific document detail page template?

As an experienced security CMS website operations personnel, I deeply understand the importance of the naming rules of the content management system (CMS) template for the long-term operation, maintenance efficiency, and content presentation quality of the website.A clear and standardized template naming not only allows team members to quickly understand the purpose of the file, reduce collaboration costs, but also provides strong flexibility and scalability when the website faces a redesign or feature upgrade.In AnQi CMS, the naming of templates for specific document detail pages follows a set of flexible and hierarchical rules, aimed at meeting the needs of content display at different granularity.

2025-11-06

How to customize the document list template for a specific category?

As a website operator who deeply understands the operation of AnQiCMS, I understand your needs for personalized content display and user experience optimization.The document list template under the custom category is the key step to achieve this goal.AnQiCMS provides a flexible template mechanism that allows you to present a unique list layout based on the content features of specific categories.

2025-11-06

How to create and apply an independent template for a specific single page (such as 'About Us')?

As an experienced website operator who deeply understands the operation of AnQiCMS, I understand that you want to create and apply an independent template for a specific single page (such as "About Us").This not only allows the page content to be displayed more personalized, but also effectively meets specific design and functional requirements.AnQiCMS provides a flexible template mechanism, making this process intuitive and efficient.### A detailed guide to creating and applying independent templates for specific single pages in AnQiCMS AnQiCMS is known for its high customizability and flexibility

2025-11-06

How to define a new template, what is the role of the `config.` file?

As an experienced CMS website operation personnel, I am well aware that a flexible and efficient template system is crucial for the presentation of website content and user experience.The AnQi CMS was designed with full consideration of the customizability and ease of use of the templates, allowing both beginners and experienced developers to easily handle it.Next, I will elaborate on how to define a new template in Anqi CMS and deeply analyze the core role played by the `config.` file in this process.

2025-11-06