In the daily operation of Anqi CMS, we often encounter the need: certain pages or content need to break away from the unified style of the website and present in a unique way.This could be to highlight an important product, create a dedicated landing page for a special topic event, or simply make the "About Us" page more brand-specific.Fortunately, Anqi CMS is renowned for its high customizability, providing us with a flexible way to set independent display templates for specific content, thus realizing this personalized display requirement.

The flexible content model and template management mechanism of Anqi CMS is the key to achieving our goal.It allows us not only to fill content, but also to deeply control the way content is presented, which is of great benefit for improving user experience, optimizing SEO, and even achieving differentiation in content marketing.

Why do you need an independent display template?

Most of the content on the website usually follows a set of unified design standards, which helps maintain brand consistency.However, there are always some 'special cases' that need special treatment.Imagine that your website has a "Download Center" page, which may need a simple layout to highlight the download buttons and descriptions; or a product promotion page, which may need an eye-catching full-screen slideshow and a form to collect potential customer information.If all these pages follow the general template, it will be difficult to achieve **the marketing effect and user conversion rate.Setting them up with an independent display template means you can tailor the visual experience and functional layout for these key contents, making them stand out among numerous content and better serve specific business objectives.

The home of template files: the template directory structure of AnQi CMS

In AnQi CMS, all template files are stored centrally under the root directory of the website/templateIn the folder. Each installed template theme will have an independent folder in this directory, for exampledefault. Inside this theme folder, you will find organized HTML files that determine the layout and style of the website's front-end pages. For example, the article detail page usually has aarticle/detail.html, there may be in the category list page,article/list.html, while the single page might be,page/detail.html. These HTML files use a syntax similar to the Django template engine (using,{{变量}}to retrieve data,{% 标签 %}Control logic to render dynamic content.

Static resources, such as CSS, JavaScript, and images, are usually stored in./public/static/Under the directory, separated from the template file, convenient for management and CDN acceleration.

How to create your exclusive template file?

The essence of creating a custom display template is to make one in the folder of the template theme you are currently using, which conforms to the Anqi CMS template rules..htmlFile. Anqi CMS provides some default template file naming conventions, such as searching for the article detail pagedetail.html, searching for the category list pagelist.html. But more importantly, it allows us to set the names for these files.Custom namesto meet the needs of specific pages.

For example, if you want to set a unique template for a specific article named "Download Center", you cantemplate/{你的模板主题名}/article/Create a file nameddownload.htmlThe file. Similarly, if your "About Us" page needs special styling, you can create atemplate/{你的模板主题名}/page/about.htmlfile. The key is, this custom.htmlThe file will be specified as the display template for the content in the subsequent backend settings.

In these custom template files, you can use various template tags provided by Anqicms as you would with other standard templates (such as{% archiveDetail %}used to obtain article details,{% pageDetail %}Used to obtain detailed information of a single page, etc.) to call the required data, and combine HTML, CSS, and JavaScript for layout and beautification.

Assign independent templates for different types of content

AnQi CMS provides an intuitive backend interface for assigning these custom templates for different types of content:

  1. Set an independent template for a specific article (document):Go to the "Content ManagementIn the document editing interface, scroll down to find a field named 'Document Template'.download.htmlAfter saving the document, the article will automatically load and use the template you specified when accessed on the front end:download.htmlto render the template.

  2. Set an independent template for a specific category:For document classification, the process is similar.Under 'Content Management', go to the 'Document Classification' page, and edit the category you want to set (for example, a subcategory under 'News Center').In the category editing page, you will see a 'category template' field in the 'other parameters' area.article/news_special_list.html. It is also worth mentioning that there is also an option for 'whether to apply to subcategories'.If you check this option, all subcategories under the current category will automatically inherit and use this custom template, which is very convenient when it comes to managing the display of certain types of sub-content uniformly.

  3. Set an independent template for a specific page:The single-page settings are equally intuitive.In the 'Page Resources' under 'Page Management', edit your single page, such as 'About Us'.page/about.htmlAfter saving, this page will display the dedicated template.

Successfully applied and注意事项

It should be noted that the custom template file you specify must truly exist within the template theme package you are using.If the template file does not exist, the corresponding page may encounter errors when accessed or may not display normally.Therefore, be sure to confirm that the template file has been uploaded to the correct location before specifying the template name in the background.

Also, if you want your website to have a unique display effect on both PC and mobile devices, then don't forget to create a custom template in the PC template directory and also within the template theme.mobileCreate the corresponding mobile template under the directory and use the same naming convention. Anqi CMS will automatically match the corresponding template based on the visited device.

Through these flexible custom template features, Anqi CMS is not just a content publishing tool, but also a powerful platform that can help you achieve diverse content presentation.It fills every corner of the website with personality and vitality, helping you to more effectively reach your target users and improve the overall operation of the website.


Frequently Asked Questions (FAQ)

1. What is the difference between custom template and content model fields?

The content model field defines the structured data of the content, such as the specific information of the article's 'author', 'source', etc., which is the 'skeleton' of the content.And custom templates determine how the 'skeleton' of these contents is dressed up in style on the front end, which is the 'skin' of the content.The template is responsible for layout, typesetting, and visual presentation, while the content model fields provide the data required by the template.Both are complementary relationships.

2. If I specify a custom template for a page but the template file does not exist, how will the page display?

If the specified custom template file does not exist, Anqi CMS will usually try to backtrack to the default general template for rendering (for example, article details will try to usearticle/detail.html, single page will trypage/detail.html)。However, this is not absolute, and under certain configurations, it may also directly cause the page to be inaccessible or display errors.Therefore, it is strongly recommended to access the front-end page immediately after setting up a custom template in the background, to ensure that the template file has been uploaded and activated correctly.

3. Can I reference other template fragments in a custom template?

Of course. The Anqi CMS template engine supports{% include "partial/header.html" %}Such a label, you can reference any code snippet of the website's public header, footer, sidebar, etc. in a custom template, and even reference other custom macro functions ({% macro %}This greatly enhances the reusability and maintenance efficiency of the template, allowing you to maintain code neat and structured while customizing individually.