How to use a custom template for specific documents, categories, or single pages in AnQiCMS?

Calendar 👁️ 62

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

Related articles

What is the default naming rule for single page detail page templates in AnQiCMS?

As an experienced CMS website operator for an enterprise, I am well aware that the exquisite presentation of content lies in the flexible application of templates.AnQiCMS as an efficient and customizable content management system provides us with powerful tools to shape every detail of the website, including the layout and style of single-page detail pages.Understanding the template naming rules is the foundation for efficiently managing and optimizing website content.

2025-11-06

How to create default templates for the model home page, document detail page, and list page of AnQiCMS?

As an experienced security CMS website operator, I am well aware of the importance of a clear and efficient template system for website content management.AnQiCMS provides a highly flexible and customizable template system that allows us to easily create personalized page layouts based on different business needs.Mastering the creation method of its default template is the foundation for efficient operation and content optimization.This article will detail how to create default templates for the model homepage, document detail page, and list page of AnQiCMS, with instructions on the use of key tags

2025-11-06

What is the naming convention for the default homepage template file in AnQiCMS?

As an experienced CMS website operation personnel of an enterprise, I know that the naming specification of template files is crucial for the smooth operation and efficient management of the website.A clear naming convention not only ensures that the system renders the page correctly, but also greatly improves team collaboration and post-maintenance efficiency.Below, I will elaborate on the naming rules of the default home page template files in Anqi CMS.In AnQi CMS, all template files are stored in the `/template` folder under the system root directory.Each independent website template will be in `/template`

2025-11-06

How to create and reference reusable code snippets (such as sidebars) in AnQiCMS templates?

As an experienced CMS website operation personnel of a security company, I know that efficiency and maintainability are the key to website content management in daily work.AnQiCMS provides a powerful and flexible template system, where creating and referencing reusable code snippets is an important means to improve these aspects of efficiency.This not only reduces repetitive labor, but also ensures the consistency of the overall style and function of the website, and also lays a solid foundation for future content updates and website renovations.

2025-11-06

What template engine syntax does AnQiCMS template support, and what are the formats of its variables and tags?

As an experienced AnQiCMS website operations personnel, I am well aware of the importance of an efficient and easy-to-use template system for website content management and user experience.AnQi CMS does an excellent job in this aspect, providing a powerful and flexible template mechanism that makes content presentation intuitive and highly customizable.Now, let's delve deeper into the syntax, variables, and tag formats supported by the AnQiCMS template.

2025-11-06

How to get and display the website name and logo in AnQiCMS template?

As an experienced CMS website operation personnel of an enterprise, I am well aware of the importance of effectively displaying brand information in templates for user experience and brand recognition.The following article will provide a detailed guide on how to obtain and display the website name and logo in the AnQiCMS template.In AnQiCMS template, a practical guide to obtaining and displaying the website name and LogoThe website's name and logo are the core visual elements of the brand

2025-11-06

How to call the contact information set in the background of AnQiCMS template?

As an experienced senior personnel proficient in AnQi CMS content operation, I am well aware of the importance of efficient website information management in attracting and retaining users.Especially contact information such as this basic yet crucial information, its unified management and flexible access are the foundation for improving operational efficiency and ensuring the accuracy of information.Below, I will introduce how to call the contact information set in the background of the AnQiCMS template.

2025-11-06

How to dynamically set the content of the `<title>`, `<meta keywords>`, and `<meta description>` tags for AnQiCMS pages?

As an experienced security CMS website operator, I know that website SEO optimization is the core work to attract and retain users, and to enhance the visibility of the website.It is crucial to accurately set the <title>, <meta keywords>, and <meta description> tags for each page (collectively known as TDK, i.e., Title, Description, Keywords).The AnQi CMS was designed with SEO-friendliness in mind from the outset

2025-11-06