Manage website content in Anqi CMS, flexibility is one of its core advantages.When you need to present a unique content layout or style for a specific document detail page, the system provides a powerful custom template function.This means that you can configure a dedicated display template for the type, content, and even the specific needs of a document, thereby breaking away from the uniformity of traditional CMS and creating more attractive and functional pages.
AnQi CMS is able to achieve this due to its flexible content model design, as well as the continuously enhanced template customization capabilities in system iterations, such as supporting custom category templates, article templates, product templates, and page templates in early versions.These features provide content operators with great freedom, ensuring that the website can adapt to various complex and changing content display needs.
How to specifically configure a custom display template for the document detail page? Anqi CMS provides two main ways for you to flexibly choose according to the actual situation.
Method one: Set a custom template through the document itself
This is the most direct and detailed control method, suitable for when you want a specific document to have a unique display effect.
When you add or edit documents in the background "Content Management", you will notice an option called "Document Template".This is the key to implementing personalized settings. You can enter the name of a template file here, for exampledownload.html. The system will find the corresponding file under the template theme directory you are using to render the details page of this document.
For example, if you have a special type of document on your website, such as a software download page, you may want it to include download buttons, version information, installation guides, and other special layouts. At this point, you can design a special one nameddownload.htmlThe template file, then fill in the 'Document Template' option when publishing this download documentdownload.htmlSo when the user accesses this download document, it will load the carefully designed one you have createddownload.htmlThe template, not the general document detail template.
It should be noted in particular that the template filename you enter must actually exist in your/templateFiles under the directory. If the file does not exist, the document detail page will not display normally.
Method two: Set a unified template through document classification.
If you want all documents under a certain category to use the same specific layout, setting up a document template through the category settings will be a more efficient choice.
In the background "Content Management", enter the editing interface of "Document Classification".Here, you will also find an option for a "document template".Similar to setting for a single document, you can enter the name of a template file here, for exampleproduct_detail_series_A.htmlOnce set and saved, all documents (articles or products) under this category will default to using this specified template to display the detail page.
Moreover, the category template settings provide an option named 'Apply to Subcategories'.If you check this option, the current category and all its subcategories will use the document template you set here.This is very convenient for managing product series or article topics with multi-level hierarchy structures, ensuring consistency in brand image and content experience.
Creating and writing the template file
The prerequisite for configuring a custom template is that you need to create these template files first and write the content within them. All template files should end with.htmland be placed in the current website theme's/templateUnder the directory. The template engine of Anqi CMS supports syntax similar to the Django template engine, users familiar with Django or Blade template syntax will find it easy to get started.
When writing a custom document detail page template, the following steps are usually followed:
- Inherit the basic layout:To maintain the consistency of the overall website style, it is recommended that your custom template passes through
{% extends 'base.html' %}Inherit your website's basic layout template in this way. This way, you only need to focus on the unique content area of the detail page. - Call document data:The core of a custom template is to display the detailed information of the document. Anqi CMS provides
archiveDetailtags to retrieve all the data of the current document. For example, to display the document title, you can use- for example, to display the document title, you can use
{% archiveDetail with name="Title" %}. - Use to get the document text content
{% archiveDetail with name="Content" %}. If the text contains HTML, please be sure to cooperate with it|safea filter such as{{ archiveContent|safe }}To ensure that the HTML content can be parsed by the browser normally rather than as plain text. If the image needs to be lazy-loaded, you can also addlazyproperties such as{% archiveDetail with name="Content" lazy="data-src" %}. - other commonly used fields, such as document links (
Link), Description (Description), Category (Category) publication time (CreatedTime), Page views (Views), Cover image (Logo) and thumbnail (Thumb), etc., can be accessed througharchiveDetailtags easily.
- for example, to display the document title, you can use
- Display custom fields:If your content model defines additional custom fields, you can use
archiveParamsLabels to retrieve and display them. This allows you to flexibly add and display personalized information for different types of content (such as product parameters, property features, etc.) - Add navigation function:In the document detail page, navigation links for "previous" and "next" articles are often needed. Anqi CMS provides
prevArchiveandnextArchivetags to easily implement this feature.
Summary
AnQi CMS provides custom template configurations at the document and category levels, granting content operators great flexibility.Whether it is to create a unique display for a specific document or to unify the style of content under an entire category, these features can help you build a rich content and excellent user experience website.Make full use ofarchiveDetail/archiveParamsetc. core tags, combinedincludeandextendsAuxiliary labels, you will be able to efficiently create and maintain various personalized document detail page templates.
Frequently Asked Questions (FAQ)
Q1: If a document is set with a custom template and also has a document template set for its category, which template will be displayed in the end?
A1: In AnQi CMS, the settings of the document itself have a higher priority than the settings of the category.Therefore, if a document specifies a custom template directly in its editing interface, even if its category is also configured with a document template, the system will ultimately prioritize the template specified by the document itself.This provides you with the most fine-grained control.
Q2: What are the naming restrictions for custom document template files?
A2: Custom template files must be named with.htmlSuffix. The filename itself should follow the operating system's naming conventions, usually it is recommended to use letters, numbers, and underscores, and avoid special characters and spaces.At the same time, to avoid conflicts with the system default template or other files in your current theme, it is best to use a file name with clear identification.Ensure that the template file is located in the current theme's/templatedirectory.
Q3: Why didn't the front page update immediately after I modified the content in the custom template?
A3: This may be due to system caching. Anqi CMS will enable caching mechanisms to improve website access speed.After you modify the template file, you may need to manually clear the system cache for the changes to take effect.You can find the 'Update Cache' feature in the background management interface, click to clear the cache, and then visit the front page again to see the latest effect.In addition, the browser cache may also affect the display, you can try clearing the browser cache or accessing in incognito mode.