When building a website, we often need to assign unique appearances and functions to different page types, such as the grand layout of the homepage, the immersive reading experience of the article detail page, or the filtering and display of the product list page.AnQiCMS provides a flexible mechanism that allows users to easily specify and manage display templates for each page of the website.This has greatly enhanced the customization of the website, as well as greatly optimized the user experience and content presentation efficiency.

The template files of the AnQiCMS website are stored in/templatethe directory. Typically, each independent website theme will have a dedicated folder in this directory, such asdefaultormy_custom_themeIn this theme folder, static resources such as CSS stylesheets, JavaScript scripts, and images will be stored separately/public/static/In the directory. Template files are usually named with.htmlAs a suffix.

AnQiCMS provides two main ways of organizing template files:Folder organization modeandFlat file organization mode. Regardless of which mode is used, the system supports a set of default template naming conventions. As long as you create template files according to these conventions, AnQiCMS can automatically recognize and apply them without any additional backend configuration. For example:

  • Home page template: Usually named asindex/index.html(Folder mode) orindex.html(Flattened mode).
  • Document detail pages (such as articles, products): Default can be named{模型table}/detail.html. For example, if it is an article model, it can bearticle/detail.html.
  • Document list page (by category): Default can be named{模型table}/list.htmlFor example,article/list.htmlUsed for article list.
  • a single page detail page: Default can be namedpage/detail.html.

Moreover, AnQiCMS also allows specifying a more detailed default template name for specific content, for example:

  • Specific document detail page:{模型table}/{文档id}.htmlThis allows you to design a dedicated template for a specific ID document.
  • Specific category list page:{模型table}/list-{分类id}.htmlYou can provide a customized layout for a list page under a specific category.
  • Specific single page:page/{单页面id}.htmlIt is used to provide a unique template for a specific ID's single page (such as the 'About Us' page').

These default naming rules greatly simplify template management, and according to these conventions, you can create templates as needed for most scenarios.

However, when you need to fine-tune the display template of a specific content (such as a special article, a specific product category, or a unique single page), AnQiCMS also provides an option to manually specify it in the backend management interface.

Specify the display template for a single document (article/product):

When you create or edit a document in the background, you can find a field named "Document Template" in the "Other Parameters" settings area of the document. Here, you can enter the custom template filename you want to use for the document, for exampledownload.htmlMake sure this file exists in your theme template directory, otherwise the document may not be accessible.This approach is very suitable for providing independent layouts for content with special display requirements (such as software download pages, special event pages).

Specify the display template for document categorization:

Under the 'Content Management' module in the background, enter the 'Document Classification' management interface. When you add or edit a category, there are two important template settings in the 'Other Parameters' area:

  1. category templateThis refers to the category underlist pageThe template used. By default, it might be{分类模型}/list.html. If you want to design a unique layout for a specific category's list page, you can enter a custom template filename here, for examplespecial_products_list.html.
  2. Document Template: This setting allows you to set for the list under the categoryAll document detail pagesSpecify a unified template. For example, if you want all products under a certain product category to use a template namedproduct_detail_v2.htmlThe template to display, you can set it here. There is also an option called 'Apply to Subcategories', if checked, the setting will be inherited by all lower-level subcategories.

Specify the display template for the single page:

In the 'Page Resources' module's 'Page Management', when you add or edit a single page, you will see an option for a 'Single Page Template'. Similar to the document, you can specify the custom template file used by this single page here, for exampleabout_us.html.

Understand template types and mobile adaptation:

AnQiCMS supports various website modes, including adaptive, code adaptation, and PC+mobile independent site modes. If your website template selects the "code adaptation" or "PC+mobile independent site" mode, then you also need to create a file in the theme folder.mobileDirectory. The directory structure and file naming conventions of the mobile template are consistent with the PC end, but they exist onlymobilein the subdirectory, for the adaptation of mobile device access.

By these methods, whether through default naming conventions or manual specification in the background, AnQiCMS gives you a high degree of flexibility to finely control the display templates of each page on the website, thereby creating a truly business and brand image website.


Frequently Asked Questions (FAQ)

  1. Q: Why did I specify a custom template file name in the background, but encountered an error when accessing the page, indicating that the template file does not exist?

    • A: This is usually caused by the mismatch between the specified template filename and the actual file path. Please check:
      • Does the template file indeed exist in the current topic's/template/你的主题文件夹/directory.
      • Is the filename spelled correctly (including case).
      • If your template file is in a subdirectory (for examplepage/about.html), make sure to include the subdirectory path when filling in the background.page/about.html.
      • Please confirm that the website theme you are currently using is the one you expected, and that the theme is enabled correctly.
  2. Q: How to distinguish between PC and mobile end templates used by AnQiCMS?

    • A: AnQiCMS supports 'code adaptation' and 'PC+mobile independent site' modes to achieve mobile adaptation. In these modes, you need to create a folder namedmobileThe subdirectory. When the system detects that the user accesses through a mobile device, it will try to find the corresponding template file in that directory first. For example, if the PC detail page template ismobiledirectory to find the corresponding template file. For example, if the PC detail page template isarticle/detail.htmlSo the corresponding template for the mobile end should be placed inmobile/article/detail.html.
  3. Q: Can I reference another template file in a template file? For example, all pages use the same header and footer.

    • A: Of course. AnQiCMS's template engine supports{% include "partial/header.html" %}and{% extends "base.html" %}TagsincludeTags are used to embed other template fragments (such as page headers, footers, sidebars), andextendsTags are used to implement template inheritance, you can create a basic skeleton template such asbase.html),then let other page templates inherit it and overwrite specific blocks. This can greatly improve the maintainability and reusability of the template.