In a content management system, we often need to present certain content of the website in a unique way, which not only meets the specific needs of branding or marketing, but also brings visitors an optimized browsing experience.AnQi CMS is well-versed in this, providing flexible template customization features, allowing us to easily specify a unique template file for a category page, or even a single content page.

Why do you need to customize a template for a specific page?

Imagine that your "About Us" page might need a special layout that includes team photos and a timeline of the company's development history, rather than simply displaying articles.Or, a product series category page where you want to display it in a grid with tag filtering, rather than the traditional list layout.Or perhaps, some thematic articles require special visual effects or interactive elements to attract readers.

The template customization feature of AnQi CMS is designed to meet these personalized needs.It allows you to break away from the same old layout, customizing exclusive display templates for key categories or single pages on the website, thereby enhancing the professionalism and user experience of the website.

Template file storage and basic conventions

Before starting customization, we need to understand the basic storage location and some conventions of the Anqi CMS template files. All template files are uniformly stored in the site's/templatethe directory and use.htmlAs a file suffix. Each independent template theme will have its own subdirectory, which contains aconfig.jsonFile description theme information.

The AnQi CMS template engine is similar to Django, variables are used with double curly braces{{变量}}While conditional judgments, loop controls, and other logical tags use single curly braces and percent signs{% 标签 %}This provides us with powerful flexibility to build the page structure.

How to specify an independent template for category pages?

When you want to apply a unique layout to a specific document category page (such as a news list page or a product list page), you can follow the following steps:

First, create a new template file in the directory of the current template theme you are using. For example, if you have a product category with an ID of10and you want it to have a specialproduct-grid-list.htmlTemplate display, you can place it intemplate/您的主题名称/product/product-grid-list.html. Here,productThe corresponding directory of your content model (such as product model).

Next, log in to the AnQi CMS backend and go to the "Document Classification" under "Content Management".Find the category of the custom template you want, click edit.At the bottom of the editing page, you will find a collapsible area named "Other Parameters", expand it.Here, you will see a 'category template' input box.

Enter the relative path and name of the template file you just created, for exampleproduct/product-grid-list.html. If you want this custom template to be inherited by all subcategory pages under it, remember to check the 'Apply to Subcategories' option.

Finally, save the category settings. When visitors visit this category page, AnQi CMS will automatically call the one you specifiedproduct-grid-list.htmlto render the content.

In addition, if you want all documents (detail pages) under this category to use the same specific template, you can also find the 'Document Template' field below 'Category Template' to set it.

How to specify an independent template for a single page?

The process of customizing a template for independent single pages like 'About Us' and 'Contact Us' is also simple and intuitive.

The first step is also to create a template file for a single page in the directory of your current theme. Suppose you want to create one for the page with ID5to create a "About Us" page.about-us.htmlTemplate, you can place it intemplate/您的主题名称/page/about-us.html.

Then, enter the AnQi CMS backend, navigate to 'Page Resources' under 'Page Management'.Find the custom single page you want, click edit.On the page editing interface, you will also see a 'Single Page Template' input box.

Enter the custom template filename here, for examplepage/about-us.htmlAfter saving the settings, when you visit this single page, the system will use the one you specifiedabout-us.htmlThe template is used to display its content.

How to specify an independent template for a single document (article/product)?

In addition to categories and single pages, Anqi CMS even allows you to specify independent display templates for specific articles or product content.

When you publish or edit documents (articles or products) under "Content Management

Here, you can enter the path of the template file prepared for this specific document, for examplearticle/unique-article-detail.htmlThis is very useful in handling some high-quality content with special display requirements, such as a deep report with multimedia elements, or a product display page that requires special configuration.

Some important notes and **practices:

  • The template file must exist:No matter where you specify a custom template, make sure that the file actually exists in the template theme directory structure you are using.If the file does not exist, the system will usually revert to the default template or report an error.
  • Use relative paths:When filling in the template name in the background, please use a relative path to the root directory of your current theme, for examplearticle/list-download.htmlinstead ofdownload.htmlor/template/您的主题/article/list-download.html.
  • Start from an existing template:When creating a custom template, a good habit is to first copy the existing default template that is closest to your needs (such asarticle/detail.htmlorpage/detail.htmlThen on this basis to make modifications. This can save the time of building the basic structure from scratch.
  • Using template inheritance:AnQi CMS template engine support{% extends 'base.html' %}This inheritance syntax. This means that your custom template can inherit the main template (such asbase.html) the common structure, only modifying the specific{% block %}The area has greatly improved development efficiency and consistency of templates.
  • Consider mobile adaptation:If your website uses "code adaptation" or "PC+mobile" mode, and the custom template needs a different layout for mobile devices, remember to do so in the theme'smobileCreate corresponding mobile template files under the subdirectory and maintain a similar filename and path structure as the PC template. For example, the PC side ispage/about-us.html, and the mobile side might bemobile/page/about-us.html.

By these flexible template customization features, Anqi CMS allows content display to be unrestricted by a single layout. You can fully express your business needs and creativity, creating a unique and captivating visual experience for the website.


Frequently Asked Questions (FAQ)

1. What will happen if the custom template file I specified does not exist?If you specify a custom template file in the background but the file does not exist in the actual template directory, Anq CMS will usually revert to the default template for the type of content (such as articles, categories, single pages) for display. For example, if an article specifies a non-existent template, the system will try to use{模型table}/detail.html.Although this does not cause the page to crash, you will find that the page layout is not the customized effect you expected.Therefore, after saving the settings, be sure to check the front-end page to confirm that the template is applied correctly.

2. Can my custom template inherit or reuse the default template's header, footer, and other common parts?Of course! The Anqi CMS template engine supports{% extends 'your_base_template.html' %}Such an inheritance mechanism. You can use it at the beginning of a custom template.{% extends 'base.html' %}(or any base template path you define), and then only{% block content %}Write your custom content in the specified area.This way, you don't have to rewrite the header, navigation, footer, and other common elements of the website, just focus on the layout and style of specific pages, greatly improving development efficiency and the unity of the overall style of the website.

3. Does using a custom template affect the SEO of the website?The custom template itself usually does not directly affect SEO ranking.SEO focuses on the content quality of the page, structured data, loading speed, mobile friendliness, URL structure, and metadata (TDK), etc.If your customized template can optimize these factors, such as improving page loading speed, enhancing user experience, ensuring clear content structure, setting up TDK tags correctly, and supporting mobile adaptation, then it will have a positive impact on SEO.On the other hand, if the template is not designed properly, it may lead to slow page loading, disorganized structure, or incompatibility with mobile devices, which could have a negative impact on SEO.The key is in the content and technical implementation of the template, not the behavior of 'customization' itself.