When using AnQiCMS to manage website content, we often need to assign unique display styles and functional layouts to specific content types or particular pages.This requirement is very common in content operation, for example, a product introduction page may need richer image display and parameter comparison, while a news article focuses on the reading experience of text; or the 'About Us' page on a website, which needs a unique corporate culture display.AnQi CMS provides flexible template customization features, allowing you to easily achieve these personalized display needs.
The template mechanism of AnQi CMS is designed very intuitively and easily understandable. It uses a Django-like template engine syntax, in.htmlAs a template file suffix, and all template files are stored in the root directory of the website./templateThis centralized management method facilitates the organization and maintenance of templates.
To set a custom template for specific content, you usually start from three main aspects: for individual documents (articles or products), for the content list page of the entire category, and for a specific single page.
Application of custom document (article/product) template
In actual operation, you may encounter situations where you need to design a unique layout for a specific article or product detail page.For example, you have posted an important event announcement and hope it has a special promotional style, or a certain star product needs a more attractive display interface.
To achieve this personalization, you can set it when editing the corresponding document in the Anqi CMS backend.In the interface for "Publishing Documentsactivity_details.htmlorstar_product.html) After saving, the document will be rendered using the template you specified.
In addition, AnQi CMS also supports a more intelligent template recognition mechanism. If you name the template file as{模型table}/{文档id}.htmlin the format (for example, if your article model table name isarticle, the document ID is123If so, the template file can be namedarticle/123.htmlThe system can also automatically recognize and apply. This means that you can prepare a template for a specific document directly by content ID, without manually specifying it in the background.
It is worth mentioning that you can also specify a 'document template' for all documents under the 'Document Classification' settings.This means that if all products under a certain product category need a unified special display template, you only need to configure it once under that category, and all new and old products will automatically follow this template, greatly enhancing management efficiency.
Category page custom template settings
The layout and functionality of the category page (such as news list, product list) may also need to be adjusted according to the content.For example, you have a 'Case Showcase' category that you want to display in a grid waterfall style, while the 'Industry News' category should be presented in a traditional list style.
For this kind of requirement, you can find the corresponding category in the "Document Category" management on the Anqi CMS backend and enter the editing interface.In the 'Other Parameters' area, there will also be a field for 'Classification Template'.case_list.html).
The Anqi CMS will use by default{分类模型}/list.htmlsuch naming conventions to render the category list page. But if you have more fine-grained control needs, you can create something like{模型table}/list-{分类id}.htmlSuch template files, the system will also prioritize identification and use. For example, if you have aproductmodel, the classification ID is456, you can createproduct/list-456.htmlFile comes to customize the list page for this specific product category.
In the settings of the classification template, there is also a very practical option called 'Apply to Subcategories'.If this option is checked, the custom template settings of the current category will be automatically inherited by all its subcategories, which can effectively reduce the workload of repeated configuration when building a website with a hierarchical structure.
Custom template application on a single page.
In addition to documents and categories, single pages on the website (such as "Contact Us
The Anqi CMS also provides independent template customization capabilities for single-page applications.In the background under 'Page Resources', in 'Page Management', when you edit or add a single page, you will see the settings for 'Single Page Template'.about_us.html.
Similar to documents and categories, the system also has default naming conventions to identify single-page templates:page/detail.htmlIt is the default template for a single page. If you want a template with a specific ID to be789The single page has a dedicated template, which can be createdpage/789.htmlfile. A more flexible approach is to create a descriptive-named template for a specific single page, such as creating a template for the "About Us" pagepage/about.htmlThen associate it with the corresponding single page in the background.
Placement and naming specifications of template files
Whether you are customizing document, category, or single page templates, all.htmlTemplate files should be stored in/templatethe root directory of the theme folder you are currently using. For example, if you are using thedefaulttheme, then the custom template is placed in/template/default/the directory.
When naming custom templates, you can determine the filename according to your habits and needs, as long as it is correctly associated in the corresponding settings in the background. For example, documents can be named asspecial_report.htmlCategory can be named asproduct_gallery.htmlPage can be named asfaq_page.htmlThe system provides two file organization modes: folder organization mode (such asarchive/detail.html) and flat file organization mode (such asarchive_detail.htmlYou can choose one according to the project scale and personal preference.But regardless of which mode you choose, the key is that the template file name you fill in the background needs to match the actual file path and name exactly.
Important reminder:
- File existence:Make sure that the custom template file specified in the background actually exists in the corresponding template directory on the server.If the file does not exist or the path is incorrect, the page will not load normally.
- Encoding format:The template file should use UTF-8 encoding to avoid Chinese garbled characters.
- Responsive design: If your website needs special adaptation for mobile devices, you can create under the template theme directory
mobile/Subdirectory, and place the exclusive mobile template files with the same structure as the PC end. - Save and clear cache:After changing the template file or backend settings, please save and clear the system cache of AnQi CMS in time to ensure that the changes take effect immediately.
With these flexible custom template features provided by Anqi CMS, you can easily achieve personalized display of website content, meet various complex operational needs, and thus create a more attractive and feature-rich website.
Common Questions (FAQ)
Q1: I customized the template file and made backend settings, but when I accessed the page, I found that the template did not take effect, and the page still displayed the default style. Why is that?An1: This situation usually has several possible causes.Please check whether the template file name you filled in the background is exactly the same as the actual file name (including case), and the file indeed exists in the template theme directory you are currently using.Secondly, the Anqi CMS has a caching mechanism. After modifying the template or backend settings, you need to manually clear the system cache in the 'Update Cache' feature on the backend to make the changes take effect.Finally, check the server file permissions to ensure the system can read your template files.
Q2: How can I get the current document, category, or single page data in a custom template to display it in the template?A2: The A2: Security CMS provides a variety of template tags to retrieve and display data. For example, in the custom template of the document detail page, you can use{% archiveDetail with name="Title" %}to obtain the document title, or{{archive.Content|safe}}Display the document content. For category details, there is{% categoryDetail with name="Title" %}. For single pages, there are{% pageDetail with name="Title" %}etc. These tags automatically recognize the context data of the current page, and you can also throughidortokenParameters specify the data to be retrieved for a specific content.
Q3: If I specify a custom template for a category, will all documents under this category also use this template?A3: Will not.The "category template" specified for the category is used to render the list page of the category (for example, displaying the list page of all articles under the category).If you want all the 'documents' under this category to use a specific detail page template, you need to find another field in the category settings, usually named 'Document Template', where you can enter the name of the detail page template you want all documents under this category to use.