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 in
page/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.