When using AnQiCMS to manage website content, we often need to assign unique display styles and functional layouts to specific content types or unique pages.This type of 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 text reading experience;Or it is a single page "About Us" on the website, which needs to show a unique corporate culture.AnQi CMS provides flexible template customization features, allowing you to easily meet these personalized display needs.
The template mechanism of Anqi CMS is designed to be very intuitive and easy to understand. It adopts the syntax of Django template engine, with.htmlAs a suffix for template files, and all template files are stored in the root directory of the website/templatein the folder. This centralized management method facilitates the organization and maintenance of templates.
To set a custom template for specific content, usually three main aspects can be considered: for individual documents (articles or products), for the content list page of the entire category, and for a specific single page.
(article/product) custom template application
In the 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 published an important event notification and hope it has a special promotional style, or a 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 documents" or editing articles/products details, there is usually a section called "Other parameters" or similar, which contains an input box named "Document template."}Here, you just need to enter the custom template filename (such asactivity_details.htmlorstar_product.htmlAfter saving, the document will be rendered using the template you specified.
In addition, Anqi CMS supports a more intelligent template recognition mechanism. If you name the template file as{模型table}/{文档id}.htmlformat (for example, if your article model table is namedarticle, the document ID is123The template file can be namedarticle/123.html), the system can also automatically recognize and apply. This means that you can prepare a template for a specific document directly according to the content ID, without manually specifying it in the background.
It is worth mentioning that you can also set 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 existing products will automatically continue to use that 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 Display' category that you want to be displayed in a grid waterfall style, while the 'Industry Information' category should be displayed 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 "Classification Template" field.Here, you can specify a custom template file to render the content list under the category (for examplecase_list.html)
Anqi CMS will default to using{分类模型}/list.htmlsuch naming conventions to render the category list page. But if you have more fine-grained control requirements, you can create something like{模型table}/list-{分类id}.htmlSuch a template file, the system will also prioritize recognition and use. For example, if you have oneproductModel, the category ID is456You can createproduct/list-456.htmlFile to customize the list page for the specific product category.
In the category template settings, 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 amount of repetitive configuration work when building a website with a hierarchical structure.
Single-page custom template usage
In addition to documents and categories, single pages on the website (such as "Contact Us", "About Us") often require unique page designs to carry specific information or interactive functions.
SafeCMS also provides independent template customization capabilities for single-page applications.In the background under "Page Resources" and "Page Management", when editing or adding a single page, you will see the settings item for "Single Page Template".Here, you can specify the custom template file to be used for this single page, for exampleabout_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 single pages. If you want an ID to be789Single page has a dedicated template that can be createdpage/789.htmlFile. A more flexible approach is to create a descriptive-named template for a specific single page, such as for the "About Us" pagepage/about.htmlThen associate it with the corresponding single page in the background.
The placement and naming conventions of template files.
No matter whether you are customizing document, category, or single page template, all of them..htmlTemplate files should be stored in/templatethe root directory of the template theme folder you are currently using. For example, if you are usingdefaulta theme, the custom template is placed in/template/default/directory.
When naming a custom template, you can determine the filename according to your habits and needs. Just make sure to correctly associate it in the corresponding settings in the background. For example, you can name a document asspecial_report.html, can be named as a categoryproduct_gallery.html, can be named as a single pagefaq_page.html. The system provides two file organization modes: folder organization mode (such asarchive/detail.html) and flattened file organization mode (such asarchive_detail.html),You can choose one according to the scale of the project and your personal preference.But no matter which pattern it is, 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 the custom template file specified in the background is actually present in the corresponding template directory on the server.If the file does not exist or the path is incorrect, the page will not load properly.
- Encoding format:Template files should use UTF-8 encoding to avoid Chinese garbled characters.
- Adapt for mobile:If your website needs special adaptation for mobile devices, you can create it in the template theme directory
mobile/Subdirectory, and place the exclusive mobile template files with the same structure as the PC end. - Save and clean up the cache:After changing the template file or backend settings, please save and clear the system cache of Anqicms in time to ensure that the changes take effect immediately.
By using these flexible custom template functions 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.
Frequently Asked 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?A1: This situation usually has several possible causes.First, please check that the template file name you have filled in the background is exactly the same as the actual file name (including case) and that the file indeed exists in the template theme directory you are currently using.Secondly, 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" function on the backend to make the changes take effect.Finally, check the server file permissions to ensure the system can read your template file.
Q2: How can I obtain the data of the current document, category, or single page in a custom template to display it in the template?A2: The Anqi CMS provides rich template tags for retrieving and displaying data. For example, in the custom template of the document detail page, you can use{% archiveDetail with name="Title" %}to retrieve the document title, or{{archive.Content|safe}}To display the document content. For category details, there are{% categoryDetail with name="Title" %}. For a single page, there is{% pageDetail with name="Title" %}etc. These tags automatically identify the context data of the current page, and you can alsoidortokenThe parameter specifies the data to be retrieved.
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' in the category to use a specific detail page template, you need to find another field in the category settings, usually named 'document template', where you enter the name of the detail page template you want to use for all documents in the category.