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

AnQiCMS template working principle overview

AnQiCMS's template system is based on Go language, using syntax similar to Django's template engine, the files are written in.htmlsuffix and are stored in the root directory of the website./templateIn the folder. Each template has its own directory, for exampledefaultThe templates will be stored in/template/default. The template uses double curly braces{{变量}}To call variables, use single curly braces and percentages{% 标签 %}Define logic labels (such as conditional judgments, loop control).

AnQiCMS's design philosophy is flexible and easy to customize, its template mechanism allows users to apply exclusive layouts to specific documents, category pages, or single-page applications on the website, thus achieving highly personalized content presentation.

Definition and Application of Custom Template

There are mainly two ways to apply custom templates to specific content in AnQiCMS:Automatic Naming ConventionandSpecify manually.

Custom template for (Archive) document

By default, AnQiCMS will use the document detail page for articles, products, and other models under the document model{模型table}/detail.htmlAs a general template. For example, the article model is used by defaultarticle/detail.html, the product model is used by defaultproduct/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 Convention:AnQiCMS supports automatic template matching based on document ID. You can create a folder named in the directory of the template you are currently using.{模型table}/{文档ID}.htmlThe file. For example, if you have a document ID of 10 for an article model, you can create onearticle/10.htmlFile. When the user accesses the article with ID 10, the system will prioritize loading this custom template.
  2. Manually specified in the backgroundIn AnQiCMS backend, when editing or publishing documents, find the 'Other Parameters' foldable box, where there is a field named 'Document Template'. You can directly enter the filename of a custom template here, for example,download.html. The system will try to find and use the specified file as the display template for the document in the current template directory.Make sure the template file you have entered actually exists in the current template theme you are using.

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.

Custom template for (Category)

AnQiCMS also allows custom templates to be set for specific category pages. By default, the category list page will use{分类模型}/list.htmlAs a general template. For example, the category list page of the article model is usedarticle/list.html, the product model is usedproduct/list.html.

If you need a category page (such as the "News Information" category list page) to have a unique layout, you can operate in the following way:

  1. Automatic Naming Convention: You can create a custom template file based on the category ID. 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.htmlThe file. When the user accesses this category, AnQiCMS will load this file first.
  2. Manually specified in the backgroundIn AnQiCMS backend, when editing categories, find the 'Other Parameters' collapsible box, where there is a 'Category Template' field. You can fill in the filename of a custom template here, for example,news_category.html. The system will use this file as the list display template for this category. Additionally, there is also a "Document Template" field in the category settings, which is used to specify the default template for all document detail pages under the category.If all articles under a category need the same special style, you can set it here, for examplenews_detail.html. There is also an option named 'Apply to subcategories'.By default, the custom category template will not be inherited to the subcategory.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 "successful cases", "partners") to better display content.

Custom template (Page) for a single page

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

To create a custom template for a single page:

  1. Automatic Naming ConventionYou can create a template based on the single page ID or its alias:
    • By ID: Create a named template in 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 the AnQiCMS backend, you can set up a "custom URL" alias (for exampleabout)。Then, you can createpage/about.htmlFile. When the user accesses this alias single page, the system will load this template first.
  2. Manually specified in the background: When editing a single page in the AnQiCMS backend, find the "Single Page Template" field. You can enter the filename of a custom template here, for examplecontact_us.htmlThe system will try to find and use the file you specified as the display template for the single page in the current template directory.

This approach is very suitable for providing customized display for key single pages of the website (such as company introduction, privacy policy), ensuring consistency of brand image and information delivery.

The template file storage location and naming convention

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

  • File type: All template files must use.htmlAs the file extension.
  • EncodingThe template file should be unified in UTF-8 encoding to avoid garbled characters.
  • Directory structureAnQiCMS supports two template organization modes:
    • Folder organization mode: such asarticle/detail.html,page/detail.htmlIt is recommended, which helps maintain the clarity of the template file.
    • Flat file organization mode: such asarticle_detail.html,page.htmlConsistent naming is key, and ensure that the system can correctly identify and load the files, which is suitable for users with fewer files or those who prefer to simplify the directory structure.

Summary of operation steps

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

Points to note

  • The template file must exist: Regardless of how a custom template is specified, it must be ensured that the corresponding.htmlThe file actually exists in the theme directory you are currently using. If the file does not exist, the page will not open normally.
  • Priority: The automatic naming convention template (such asarticle/10.html) usually has a higher priority, and it will take precedence over the manually specified template. While the manually specified template has a higher priority than the default template.
  • UTF-8 EncodingMake sure all template files are saved in UTF-8 encoding to prevent Chinese content from displaying as 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.


Frequently Asked Questions (FAQ)

  1. What will happen if the custom template file I specified does not exist?If AnQiCMS tries to load a non-existent custom template file, the page will not display normally, usually resulting in a 404 error or a system error page indicating that the specified template file cannot be found.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 the template loading priority follows the principle of special to general:

    • Highest priority: automatically naming the template files according to the convention (for examplearticle/10.htmlorpage/about.html)
    • Second highest priority: Template file manually specified in the background management interface (for example, the document template field filled in)custom_article.html)
    • Lowest priority: The default general template corresponding to the content type (for example,article/detail.htmlorpage/detail.htmlThis means, if it existsarticle/10.htmland the backend has specifiedcustom_article.htmlthe system will use it firstarticle/10.html.
  3. Can I reference other template files in the custom template?Can. AnQiCMS template engine supportsincludeandextendsTags, you can use them in custom templates