As an experienced AnQiCMS website operation personnel, I am well aware of the importance of content in attracting and retaining users, and the flexible template system is the key to achieving personalized content display.AnQiCMS provides powerful custom template functionality, allowing operations personnel to create unique page layouts and styles based on the needs of different content.

Overview of the template working principle of AnQiCMS

AnQiCMS's template system is based on Go language, using syntax similar to Django's template engine, files are.htmlEnglish suffix, and统一存放在网站根目录下的/templateEnglish folder. Each set of templates has an independent directory, for exampledefaultEnglish templates will be stored in/template/default. The template internally uses double curly braces{{变量}}Call a variable, through single curly braces and percent signs{% 标签 %}Define logical labels (such as conditional judgment, loop control).

The design philosophy of AnQiCMS is flexible and customizable, and its template mechanism allows users to apply dedicated layouts for specific documents, category pages, or single pages on the website, thereby achieving highly personalized content presentation.

The definition and application of custom templates

There are mainly two ways to apply custom templates to specific content in AnQiCMS:Automatic naming conventionsandManually specified.

The custom template for documents (Archive)

By default, AnQiCMS will use the document detail page for articles, products, and other models{模型table}/detail.htmlAs a general template. For example, the article model defaults to usingarticle/detail.html, the product model defaults to usingproduct/detail.html.

However, when you want an article or a product to have a completely different display style, you can apply a custom template:

  1. Automatic naming conventions:AnQiCMS supports automatic matching of templates based on document ID. You can create a folder named{模型table}/{文档ID}.htmlThe file. For example, if you have a document ID of 10 for an article model, you can create aarticle/10.htmlFile. When the user accesses the article with ID 10, the system will load this custom template first.
  2. Manual specification on the backendIn AnQiCMS backend, when editing or publishing documents, find the 'Other Parameters' collapse box, where there is a field named 'Document Template'. You can directly enter the filename of the custom template here, for example,download.html.The system will try to locate and use the file you specify as the display template for the document in the current template directory.Please make sure that the template file you filled out actually exists in the template theme you have enabled.

Through these two methods, you can provide a customized page experience for special content such as 'Recruitment Information' articles, 'Contact Us' products, and so on.

分类(Category)的自定义模板

AnQiCMS 同样允许为特定分类页面设置自定义模板。默认情况下,分类列表页会使用 English 模板。{分类模型}/list.htmlAs a general template. For example, the classification list page of the article model usesarticle/list.html, the product model usesproduct/list.html.

If you need a category page (such as the 'News Information' category list page) to have a unique layout, you can operate as follows:

  1. Automatic naming conventions:You can create a custom template file according to the category ID. In the current template directory, create a file named{模型table}/list-{分类ID}.htmlThe file. For example, if there is a category ID of 5 "Company News" under the article model, you can createarticle/list-5.htmlFile. When the user accesses this category, AnQiCMS will load this file first.
  2. Manual specification on the backendIn AnQiCMS backend category editing, find the 'Other Parameters' collapse box, where there is a 'Category Template' field. You can enter the custom template filename here, for example,news_category.html.The system will use this file as the list display template for this category. Additionally, there is a 'Document Template' field in the category settings, which is used to specify the default template for all document detail pages under this category.news_detail.html. There is also an option named “Apply to subcategories”.By default, custom category templates are not inherited to subcategories.If this option is selected, all subcategories under this category will use the custom template set by the parent category.

Through these settings, you can design unique category pages for different types of categories (such as “Success Stories”, “Partners”) to better display content.

Single-page (Page) Custom Template

Single-page is usually used for independent pages such as "About Us", "Contact Information", "Legal Statement", etc. By default, AnQiCMS single-page will usepage/detail.htmlas a general template.

To create a custom template for a single page:

  1. Automatic naming conventionsYou can create a template by using the single page ID or its alias.
    • By ID: Create a file named under the current template directory,page/{单页面ID}.htmlThe file. For example, a single-page ID of 20 can be createdpage/20.html.
    • By alias: When editing a single page in AnQiCMS backend, you can set a "custom URL" alias for it (for exampleabout). Then, you can createpage/about.htmlFile. When the user accesses this alias single page, the system will load this template first.
  2. Manual specification on the backendIn AnQiCMS backend, find the "Single Page Template" field when editing a single page. You can fill in the custom template filename here, for example,contact_us.htmlThe system will try to find and use the file you specified as the display template for this single page in the current template directory.

This method is very suitable for providing customized display for key single-page websites (such as company introduction, privacy policy), ensuring consistency of brand image and information delivery.

Template file storage location and naming conventions

All custom template files should be placed in the currently enabled theme./template/{主题名称}/the directory.

  • File type: All template files must use.htmlas the file extension.
  • Encoding:The template file should be unified in UTF-8 encoding to avoid garbled characters issues.
  • Directory structure:AnQiCMS supports two template organization modes:
    • Folder organization modeFor example:article/detail.html,page/detail.htmlThis is a recommended structure, which helps maintain the clarity of the template file.
    • Flat file organization modeFor example:article_detail.html,page.htmlEnglish, suitable for users with fewer files or a preference for simplified directory structures. No matter which mode is used, the key is to maintain consistency in naming and ensure that the system can correctly identify and load.

Operation steps summary

  1. Select or create a template fileCreate a new one based on requirements,.htmlOr copy an existing template file to modify it.
  2. Place the template file:Upload the new template file to/template/{您的主题目录}/at the corresponding location (e.g.,article/folder for articles,page/folder for single pages).
  3. Specify the template in the background:
    • Document:Edit a specific document, enter the filename of the 'Document Template' in the 'Other Parameters'.
    • Category:Edit a specific category, enter the filename of the 'Category Template' in the 'Other Parameters'.
    • single page:Edit a specific single page, enter the template file name in the "Single Page Template".
  4. Verify:Visit the corresponding front-end page, check if the custom template is applied correctly.

Precautions

  • The template file must existNo matter which way you specify the custom template, you must ensure that the corresponding.htmlFile actually exists in the theme directory you are currently using. If the file does not exist, the page will not open normally.
  • Priority: Templates named by the automatic naming convention (such asarticle/10.html)usually has a higher priority, and it will take precedence over the manually specified template in the background. The manually specified template has a higher priority than the default template.
  • UTF-8 encodingEnsure that all template files are saved with UTF-8 encoding to prevent Chinese content from displaying garbled.

By following these detailed steps and instructions, you can flexibly customize templates for any specific document, category, or single-page application on the AnQiCMS website, thereby achieving a rich and powerful content display.


Common Questions and Answers (FAQ)

  1. What happens if the custom template file I specify does not exist?如果 AnQiCMS 尝试加载一个不存在的自定义模板文件,页面将无法正常显示,通常会导致 404 错误或系统报错页面,提示找不到指定的模板文件。Therefore, after specifying or naming the template file in accordance with the convention in the background, be sure to confirm that the file has been uploaded and the path is correct.

  2. What is the priority of the custom template?AnQiCMS template loading priority follows the principle from special to general:

    • Highest priority: Automatically named conventions for template files (such asarticle/10.htmlorpage/about.html).
    • Second highest priority:Back-end management interface manually specified template files (e.g., document template fields filled in)custom_article.html).
    • Lowest priority:Default general template for corresponding content type (e.g.,)article/detail.htmlorpage/detail.html). This means that if it existsarticle/10.html, and the background has specifiedcustom_article.html, the system will use it firstarticle/10.html.
  3. Can I reference other template files in the custom template?Can. AnQiCMS's template engine supportsincludeandextendsTags, you can use in custom templates