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 not only enhances the customization level of the website, but also greatly optimizes the user experience and content presentation efficiency.
AnQiCMS website template files are stored uniformly in/templateIn the directory. Typically, each independent website theme will have a dedicated folder in this directory, for example,defaultormy_custom_themeIn this topic folder, static resources such as stylesheets (CSS), JavaScript scripts, and images will be stored separately./public/static/In the catalog. The template file itself is usually named with.htmlsuffix.
AnQiCMS provides two main ways to organize template files:Folder organization modeandFlat file organization mode.No matter 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.
- Home page templatewhich is usually named
index/index.html(folder mode) orindex.html(Flattened mode). - Document detail page (such as articles, products): The 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): The default can be named
{模型table}/list.htmlFor example,article/list.htmlUsed for article list. - Single Page Detail Page: The default can be named
page/detail.html.
In addition, AnQiCMS also allows specifying a more detailed default template name for specific content, such as:
- Specific document detail page:
{模型table}/{文档id}.htmlThis allows you to design a dedicated template for a document with a specific ID. - List page of a specific category:
{模型table}/list-{分类id}.htmlA customized layout can be provided for the list page under a specific category. - Specific single page:
page/{单页面id}.htmlProvided for a single-page with a specific ID to offer a unique template (such as the "About Us" page).
These default naming rules greatly simplify template management, and for most scenarios, creating templates according to these conventions is sufficient.
However, when you need to finely control the display template of a specific content (such as a special article, a specific product category, or a unique single page), AnQiCMS also provides the 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 the document to use, such asdownload.html.Make sure that 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 classification:
Under the "Content Management" module in the background, enter the "Document Category" management interface. When you add or edit a category, there are two important template settings in the "Other Parameters" area:
- Category TemplateThis refers to the category under which it is.List pageThe template used. By default, it may be:
{分类模型}/list.htmlIf you want to design a unique layout for a specific category list page, you can enter a custom template filename here, for examplespecial_products_list.html. - Document template: This setting allows you to specify for the category belowAll document detail pagesSpecify a unified template. For example, if you want all products under a certain product category to use a template named
product_detail_v2.htmlTo display the template, you can set it here. There is also an option for 'Apply to Subcategories'. If checked, this setting will be inherited by all lower-level subcategories.
Specify display template for single page:
In the 'Page Resources' module, under 'Page Management', when you add or edit a single page, you will see an option for 'Single Page Template'. Similar to the document, you can specify the custom template file used by the single page here, such asabout_us.html.
Understanding template types and mobile adaptation:
AnQiCMS supports various website modes, including responsive, code adaptation, and PC+mobile independent site modes. If your website template has chosen the 'code adaptation' or 'PC+mobile independent site' mode, then you also need to create a folder within the theme directory.mobileContents. The directory structure and file naming conventions of the mobile template are consistent with the PC end, just that they exist inmobilesubdirectories, used to adapt to mobile device access.
Through these methods, whether through default naming conventions or manual specification in the background, AnQiCMS grants you a high degree of flexibility to finely control the display templates of various web pages, thereby creating a truly business-oriented and brand-image-matching website.
Common Questions (FAQ)
Q: I have specified a custom template filename in the background, but an error occurs when accessing the page, indicating that the template file does not exist. What could be the reason?
- A: This is usually caused by the mismatch between the specified template filename and the actual file path. Please check:
- Does the template file really exist in the current theme?
/template/你的主题文件夹/the directory. - Is the filename spelled correctly (including capitalization)?
- If your template file is in a subdirectory (for example)
page/about.html), please make sure to include the subdirectory path when filling in the backgroundpage/about.html. - Please confirm that the website theme you are currently using is the one you expect, and that the theme is enabled correctly.
- Does the template file really exist in the current theme?
- A: This is usually caused by the mismatch between the specified template filename and the actual file path. Please check:
Q: How to differentiate between PC and mobile end to use different templates in AnQiCMS?
- A: AnQiCMS supports "code adaptation" and "PC + independent mobile site" modes to achieve mobile adaptation. In these two modes, you need to create a folder named
mobileThe child directory. When the system detects that the user is accessing through a mobile device, it will try to find the corresponding template file in this directory first.mobiledirectory to find the corresponding template file. For example, if the PC detail page template isarticle/detail.htmlThen the corresponding template for the mobile end should be placed inmobile/article/detail.html.
- A: AnQiCMS supports "code adaptation" and "PC + independent mobile site" modes to achieve mobile adaptation. In these two modes, you need to create a folder named
Q: Can I reference another template file in a template file? For example, all pages use the same header and footer.
- A: Of course, you can. AnQiCMS's template engine supports
{% include "partial/header.html" %}and{% extends "base.html" %}etc. tags.includetags are used to embed other template fragments (such as headers, footers, sidebars), andextendsLabels are used to implement template inheritance, you can create a base skeleton template (such asbase.htmlThen let other page templates inherit it and overwrite specific blocks within it. This can greatly enhance the maintainability and reusability of the templates.
- A: Of course, you can. AnQiCMS's template engine supports