As a website operator who deeply uses Auto CMS, I know that the flexibility of content display is crucial for attracting and retaining users.This aspect provides strong support from AnQi CMS, allowing us to specify exclusive template files for specific categories, articles, even independent pages, thus achieving highly customized content presentation.This not only helps to improve the user experience, but also provides great convenience for us to carry out refined operation and SEO optimization.
Overview of AnQiCMS template mechanism
The Anqi CMS adopts a flexible template engine, whose syntax is similar to Django.This makes template creation and customization relatively easy.The system will automatically apply the corresponding general template based on the content type (such as articles, products, single pages) and content model (such as article model, product model).However, when we need to break away from this generality to design a dedicated visual and functional layout for a special category page, an important article, or a unique single page, Aanqi CMS allows us to achieve this in two main ways: first, by following the preset default template naming rules, and second, by manually specifying the template file in the backend management interface.
The introduction of this mechanism allows content to no longer be limited to a single layout mode. We can create unique display effects for each part of the website based on different needs such as marketing activities, content characteristics, or user groups.
Specify an independent template for a specific category
In the AnQi CMS, the category page is a key node for aggregating similar content. To make different category pages have their own styles, we can specify independent templates for them.
Firstly, the safe CMS provides some default naming conventions for the category list page. For example, if your category belongs to a model (such asarticlemodel), the system will first look for a name namedarticle/list-{分类ID}.htmlThe template file. If this file does not exist, it will fallback toarticle/list.htmlAs the default category list template. This convention mechanism reserves the possibility for us to make an initial distinction at the template level.
Further customization can be completed on the back-end management interface.When you edit a category, you will find a setting item named "Category Template" in the "Other Parameters" area.news_list.htmlThe template. Once saved, the category and its content will be rendered according to this specified template file.
In addition, there is an option called 'Apply to Subcategories' in the category settings.Select this option and all subcategories at all levels under this category will inherit and use the custom category template you set. This is very practical for scenarios where it is necessary to maintain a consistent style for a certain content line.article_detail.htmlto ensure that the articles in the category have a consistent page layout.
Specify an independent template for a specific article
Each article may carry different information, some articles require a special display method. The Anqi CMS allows us to specify a unique template for individual articles.
The system also sets default template search rules for the article detail page. For articles belonging to a specific model, such asarticleArticles under the model, the system will prioritize searching forarticle/detail-{文章ID}.htmlThe template in form. If not found, it will usearticle/detail.htmlAs the general article detail template.
On the article publication or editing page, navigate to the 'Other Parameters' section to find the settings for 'Document Template'. Here, you can enter a custom template filename, such asspecial_report.htmlWhen the user accesses this specific article, the CMS will no longer use the default article detail template, but will prioritize the one you specify.special_report.htmlPerform rendering. This allows us to provide fully customized layouts and features for some important content (such as promotional pages, special reports, or download pages).
Specify an independent template for a specific single page
Single-page (such as "About UsThe single-page also provides flexible template customization capabilities.
For a single page, Auto CMS will default to searching forpage/detail-{单页ID}.htmlSuch template files. If the file does not exist, it will usepage/detail.htmlAs a general template for all single pages.
When editing any single page in "Page Managementabout_us_custom.html.The system will prioritize loading and using this custom template when rendering the single page.This approach allows each single page to have exclusive layout and interaction design, for example, a 'Contact Us' page can integrate maps, forms, and other specific elements, while a 'About Us' page can adopt timelines, team introductions, and other rich media displays.
Template file storage location and naming conventions
All custom template files should be stored in the/templatedirectory. Template files must use.htmlas the file extension.
When organizing template files, you can follow the directory structure recommended by Safe CMS. For example, templates related to articles and categories can be placed in{模型table}/directory, such asarticle/list.htmlorproduct/detail.html. Templates related to single pages can be placed inpage/directory, such aspage/detail.html. When we specify a custom template file, we only need to provide the path and filename relative to the current themetemplatein the category template.download.html,The system will go to the current topic'stemplatedirectory to finddownload.htmlfile. If your custom template wants to follow some logical grouping, for example, to put all download-related page templates intodownload/In the directory, then when specified in the background, it needs to be filled indownload/download.html.
No matter which method you use, make sure that the template file you specify actually exists in the correct location, and the file encoding is UTF-8, which is the foundation for the normal operation of the template.
Precautions
When specifying independent templates for specific categories, articles, or single pages, there are several points to pay special attention to:
The template file you specified must exist in the current active template theme directory.If the file path or file name is spelled incorrectly, or the file itself is missing, the system will not be able to find and apply the template, which may cause the page to display abnormally or even become inaccessible.
When specifying a template via the backend, please ensure that the input file name contains the correct relative path (if the file is not in the root directory). For example, if the template file you created is located in/template/custom/my_template.htmlThen, when entering in the background, it should be enteredcustom/my_template.html.
The template file must maintain UTF-8 encoding, especially when editing template files in the Windows environment, make sure to save the file in UTF-8 format to avoid garbled characters.
Through the above mechanism, the CMS of Anqi provides website operators with great freedom, allowing for precise customization of different content, thereby better serving our website goals and user base.
Frequently Asked Questions
If I specify a template for a category but no template is specified for the articles under that category, which template will the article use?
If a category is specified with a custom "category template" (for examplenews_list.htmlThis only affects the list page display of this category.For the article detail page under this category, if the article itself does not specify an independent 'document template', then the article will use the file specified in the 'document template' field of the category setting preferentially.{模型table}/detail.html.
How does AnQiCMS determine if a template file exists?
AnQiCMS when processing template requests, will build the complete template file path based on the background configuration or default naming rules. Then, the system will directly check if there is a corresponding file under this path..htmlFile.This is a direct check at the file system level.If the file exists, it will be loaded and rendered; if it does not exist, it will follow the predefined fallback logic (such as searching for a generic template) or will report an error.
Can I create a brand new page type, rather than the existing categories, articles, or single pages, and assign it an independent template?
The core content types of AnQi CMS are categories, articles, and single pages, which are supported by different content models.If you need to create a completely new page type, the usual practice is to create a new content model to hold this type of data, or to use the existing single-page feature.special_landing_page.htmlCompletely control the page content and layout.Add a new page type that is unrelated to the existing content model and specify a template via code, then a second-level development is required.