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 powerful custom template functionality.This means that you can configure a dedicated display template for each document based on its type, content, and even individual document requirements, thus breaking away from the uniformity of traditional CMS and creating more attractive and functional pages.
Auto CMS can achieve this due to its flexible content model design and continuously enhanced template customization capabilities in system iterations, such as supporting custom category templates, article templates, product templates, and page templates since the early versions.These features provide great freedom for content operators, ensuring that the website can adapt to various complex and variable content display needs.
How to configure custom display templates for document detail pages? Anqi CMS provides two main methods for you to flexibly choose according to the actual situation.
途径一:通过文档自身设置自定义模板
这是最直接也最细致的控制方式,适用于您想让某一篇具体的文档拥有与众不同的展示效果。
When you add or edit documents in the background “Content Management”, you will notice an option named “Document Template”.This is the key to implementing personalized settings.download.htmlThe system will look for the corresponding file under the current template theme directory based on this name to render the detail 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 time, you can design a special layout nameddownload.htmlThe template file, then fill in the 'Document Template' option when publishing this download documentdownload.html. When users visit this download document, it will load the one you have carefully designeddownload.htmlTemplate, rather than a general document detail template.
It should be noted that the template filename you enter must actually exist in your/templateThe file under the directory. If the file does not exist, the detail page of this document will not display normally.
Method two: Through the document classification setting to set a unified template
If you want all documents under a certain category to have the same specific layout, using category settings to set a document template would be a more efficient choice.
In the background "Content ManagementHere, you will also find an option for a "document template".product_detail_series_A.html. Once set and saved, all documents (articles or products) under this category will use the specified template to display the detail page by default.
In addition, the classification template settings also 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 hierarchical structures, ensuring consistency in brand image and content experience.
Creating and writing the content of the template file.
The prerequisite for configuring custom templates is that you need to create these template files first and write the content within them. All template files should end with.htmland be stored in the current website theme's/templateThe template engine of the safe CMS supports syntax similar to Django template engine, which makes it easy for users familiar with Django or Blade template syntax to get started.
When writing a custom document detail page template, it is usually followed by the following steps:
- Inherit basic layout:To maintain the consistency of the overall style of the website, it is recommended that your custom template go through
{% extends 'base.html' %}Inherit your website's basic layout template in this way. Thus, you only need to focus on the content area that is unique to the detail page. - Call document data:The core of the custom template is to display the detailed information of the document. The Anqi CMS provides
archiveDetailtags to obtain all the data of the current document.- For example, to display the document title, you can use
{% archiveDetail with name="Title" %}. - Get the document text content, then use
{% archiveDetail with name="Content" %}. If the text contains HTML, please be sure to use it with|safeFilter, such as{{ archiveContent|safe }},to ensure that the HTML content can be normally parsed by the browser instead of being displayed as plain text. If the image needs lazy loading, you can also addlazyattribute, such as{% archiveDetail with name="Content" lazy="data-src" %}. - other commonly used fields, such as document links (
Link) and the description (Description)、所属分类 (English)Category), publishing time (CreatedTime) views (Views)、封面图 (English)Logo) and Thumbnail (Thumb) 等,都可以通过(English)archiveDetailTags are easily obtained.
- For example, to display the document title, you can use
- 展示自定义字段:如果您的内容模型定义了额外的自定义字段,您可以使用
archiveParamsTags can be used 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 functionality:In the document detail page, it is often necessary to have 'Previous' and 'Next' navigation links. Anqi CMS provides
prevArchiveandnextArchivetags, allowing you to easily achieve this function.
Summary
The AutoCMS provides high flexibility for content operators by offering custom template configurations at the document and category levels.Whether it is to create a unique presentation for a specific document or to unify the style for all content under a category, these features can help you build a website with rich content and excellent user experience.archiveDetail/archiveParamsetc. core tags, combined withincludeandextendsEnglish auxiliary tags, you will be able to efficiently create and maintain various personalized document detail page templates.
Common Questions and Answers (FAQ)
Q1: If a document is set with a custom template and its category also has a document template set, which template will be used to display?
Q2: Custom document template file naming restrictions?
A2: Custom template files must be named.htmlEnglish suffix.The filename should follow the naming conventions of the operating system, usually recommended to use letters, numbers, and underscores, and avoid using special characters and spaces.Also, 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./templatethe directory.
Q3: Why does the front page not update immediately after I modify the content in the custom template?
A3: This could be due to system cache.The website speed is improved by enabling the cache mechanism. EnglishWhen you modify the template file, you may need to manually clear the system cache to make the changes 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.