As a deep user of Anqi CMS website operators, I know that the flexibility of content display is crucial for attracting and retaining users.AnQi CMS provides strong support in this regard, allowing us to specify dedicated template files for specific categories, articles, and even independent pages, thus achieving highly customized content presentation.This not only helps to improve the user experience, but also provides great convenience for our fine operation and SEO optimization.
AnQiCMS template mechanism overview
AnQi CMS adopts a flexible template engine, whose syntax is similar to Django.This makes template creation and customization relatively easy to master. The system defaults to applying 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, Anqicms allows us to achieve this in two main ways: first, by following the predefined default template naming rules, and second, by manually specifying the template file for the content in the backend management interface.
The introduction of this mechanism allows content to be no longer limited to a single layout mode, and we can create unique display effects for different parts of the website based on marketing activities, content characteristics, or the different needs of user groups.
Specify an independent template for a specific category
In AnQi CMS, the category page is a key node for aggregating similar content. In order for different category pages to have their own styles, we can specify independent templates for them.
Firstly, AnQi CMS provides some default naming conventions for the category list page. For example, if your category belongs to a certain model (such asarticlemodel), the system will first look for the name namedarticle/list-{分类ID}.htmlThe template file. If the file does not exist, it will revert toarticle/list.htmlAs the default category list template. This convention mechanism reserves the possibility for preliminary distinction at the template level.
Further customization can be completed in the backend management interface.When you edit a category, in the "Other Parameters" area, you will find a setting item named "Category Template".Here, you can enter a custom template filename, for example, to specify a filename for a category named "Latest News"news_list.htmlThe template. Once saved, the category and its content will be rendered according to this specified template file.
In addition, there is also an option in the category settings for whether it should be applied to subcategories.After checking this option, all sub-categories under this category will inherit and use the custom category template you set, which is very useful for scenarios where you need to maintain a unified style for a certain content line.At the same time, you can also find the option 'Document Template' in the settings of this category, to set a uniform detail template for all documents under the current category (whether they have specified a template themselves or not), for examplearticle_detail.htmlTo ensure that the articles within the category have a consistent page layout.
Specify an independent template for a specific article
Each article may carry different information, and some articles may require a special display method. 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 that belong to a specific model, for examplearticleThe articles under the model will be searched first.article/detail-{文章ID}.htmlThe template is used. If not found, it will usearticle/detail.htmlAs a general article detail template.
On the article posting or editing page, by navigating to the 'Other Parameters' section, you can find the settings for the 'Document Template'. Here, you can enter a custom template filename, such asspecial_report.htmlWhen the user accesses this specific article, AnQi CMS will no longer use the default article detail template, but will prioritize the one you specifyspecial_report.htmlRender this. 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
A single page (such as "About Us", "Contact Us") usually has independent and infrequently changing content, and it often requires a unique brand image and information presentation style.The AnQi CMS also provides flexible template customization capabilities for single-page websites.
For a single page, Anqi CMS will default to searchingpage/detail-{单页ID}.htmlfor such a template file. If the file does not exist, it will usepage/detail.htmlAs a common template for all single pages.
When editing any single page in "Page Management", you can also find the "Single Page Template" settings in the background. Here, you can specify a particular template file for the current single page, such asabout_us_custom.html. The system will first load and use this custom template when rendering the single page.This approach allows each single page to have its own unique layout and interactive design, for example, a "Contact Us" page can integrate maps, forms, and other specific elements, while an "About Us" page can adopt timelines, team introductions, and other rich media displays.
The location and naming convention of template files
All custom template files should be stored in the directory of the currently enabled template theme/template. The template files must use.htmlas the file extension.
When organizing template files, you can follow the directory structure recommended by Anqi CMS. For example, templates related to articles and categories can be placed in{模型table}/the directory, such asarticle/list.htmlorproduct/detail.html. Single-page related templates can be placed inpage/the directory, such aspage/detail.html. When specifying a custom template file, just provide the path relative to the current themetemplateThe directory path and filename is sufficient. For example, if you fill in the classification templatedownload.htmlthe system will go to the current topic'stemplatedirectory to finddownload.htmlFile. If your custom template wishes to follow some logical grouping, for example, to put all download-related page templates indownload/the directory, then it needs to be filled in when specified in the backgrounddownload/download.html.
In any case, ensure that the template file you specify indeed exists in the correct location, and that the file encoding is UTF-8, which is the foundation for the normal operation of the template.
Points to note
When specifying an independent template for a specific category, article, or single page, 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 using a template specified by the background, please ensure that the input filename includes the correct relative path (if the file is not in the root directory). For example, if the template file you create is located in/template/custom/my_template.htmlSo, enter in the backgroundcustom/my_template.html.
The template file needs to maintain UTF-8 encoding, especially when editing template files in the Windows environment, be sure to save the file in UTF-8 format to avoid garbled characters.
Through this mechanism, AnQi CMS grants website operators great freedom, enabling them to design content accurately for different purposes, thus better serving our website goals and user groups.
Frequently Asked Questions
If I specify a template for a category, but the articles under this category do not specify a template, which template will the article use?
If a category specifies a custom 'category template' (for examplenews_list.htmlThis only affects the list page display of the category. For the detail page of articles under this category, if the article itself does not specify an independent "document template", then the article will prioritize using the file specified in the "document template" field of the category settings.If the category does not specify a document template either, the system will fall back to the general detail template of the content model to which the article belongs (for example, the article model), which is usually{模型table}/detail.html.
How does AnQiCMS determine if a template file exists?
AnQiCMS handles template requests by constructing the complete template file path based on backend configuration or default naming rules. Then, the system will directly check if the corresponding path exists..htmlFile. This is a direct check at the file system level. If the file exists, it is loaded and rendered;If not found, it will follow the predefined fallback logic (such as searching for a generic template) or report an error.
Can I create a completely 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 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.For example, you can create a single page and specify a completely custom template file in its backend settings (for examplespecial_landing_page.html),to achieve full control over page content and layout. Adding a brand new page type unrelated to the existing content model and specifying a template would require secondary development.