As a senior CMS website operation person in charge of information security, I know the importance of flexible template customization for website content display and user experience.The Anqi CMS provides us with great freedom to manage and display content with its simple and efficient architecture.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 needs.
Overview of the template mechanism of Anqi CMS
Auto CMS adopts syntax similar to Django template engine, template files are usually named with.htmlFor suffix, and stored uniformly/templateDirectory.This mechanism allows us to highly customize the appearance and layout of the website.The system supports various template types such as adaptive, code adaptation, and independent PC+mobile sites to meet different terminal access needs.For template creators, understanding the file organization conventions and naming rules is crucial.
The organization pattern of template files and the default convention
English CMS provides two template file organization modes: folder organization mode and flat file organization mode.No matter which mode is used, the system supports a series of default custom template names.This means that as long as we create files that conform to these naming conventions in the template directory, 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 find{模型table}/{文档id}.htmltemplate files in the format. If the model table name isarticle, the document ID is10, then the system will try to loadarticle/10.html. Similarly, the document list page will find{模型table}/list-{分类id}.htmlWhile single-page will searchpage/{单页面id}.htmlThese predefined naming rules provide us with a quick way to implement personalized content display, such as creating a unique layout for a specific article ID or category ID.
Through the back-end specified custom template name
In addition to the system default automatic recognition conventions, 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 valid template filename and associate it with specific website content.
For a single-page example, if we need to design a unique template for the "About Us" page, we can first create a template namedpage/about.htmlThe template file. Then, in the background "Page Managementabout.html. The system will automatically search and apply according to the specified information from the background when loading this single pagepage/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 a dedicated download template for this document. For document categories, there is also a "Category Template" field on the "Document Category" editing page, which can specify such asproduct-list.htmlAs the list template of this category.It is worth noting that the classification template also supports the option of 'whether to apply to subcategories', which allows us to apply the custom template in bulk to all subcategories below.
Ensure the correct application of the custom template
When using a custom template name, there are several key points to remember.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.about.htmlordownload.html),而不是完整的路径。系统会根据内容类型自动寻找其在模板目录中的对应位置。
Finally, to maintain the clarity and maintainability of the template code, it is recommended to make the custom template names as descriptive as possible and follow certain naming conventions. For example, 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 template customization, whether through the system's default naming conventions for automatic recognition or through manual specification of specific templates in the background, provides website operators with powerful tools to create unique content displays.
Common Questions and Answers (FAQ)
1. I have specified a custom template (such asmy_special_article.html) at the background, and the system also has a template that matches the automatic recognition rules (such asarticle/detail-10.htmlWhat 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 match the automatic recognition rules, the system will prioritize the manual configuration you have set up in the background.my_special_article.htmlThis design ensures that you can have the most precise 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 child categories under this category use this template?
Yes, if the option 'Apply to subcategories' is checked, this custom category template will be applied to the current category and all of its direct and indirect subcategories, unless a subcategory has specified another custom template separately 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 the page displays a blank or error when accessed, 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:
- Ensure that the template file has been uploaded correctly.
/templateIt is within the template design package you are currently using under the directory. - Confirm that the naming of the template file matches the name you have configured in the background exactly (including case).
- Based on content type, ensure the file is located in the correct subdirectory (for example, single-page templates should be
page/in the directory, document detail templates may be{模型table}/Directory under). - Check if the template file itself has syntax errors, as these errors may also cause the page to fail to render correctly.