How to customize the display template for specific articles, categories, or single pages to achieve personalized layout?

Calendar 👁️ 61

In website operation, providing exclusive display methods for specific content can significantly improve user experience and content marketing effectiveness.AnQiCMS (AnQiCMS) is well-versed in this, providing flexible and diverse template customization features, allowing you to easily create unique personalized layouts for articles, categories, or single pages.

There are mainly two ways to implement personalized template customization in Anqi CMS: one is to follow specifictemplate file naming conventions, the system will automatically recognize and apply; the other is toManually specify the background management interfaceCustom template file.


I. Automatic identification through template file naming conventions

The design of Anqi CMS considers the general needs of daily content management and presets some naming rules for template files.If your template file follows these rules, the system will automatically apply them to the corresponding articles, categories, or single pages without any additional backend settings.

These naming conventions are mainly based on the ID or model table name of the content. For example:

  • For a specific article detail page:You can name the template file as{模型table}/{文档id}.html. Assuming you have an article model, the model table name might bearticle.If you want to set for ID of10(such as an important thematic article) create a dedicated template, you can name the template file asarticle/10.html Place it in the template directory of the current theme. When the user accesses the article with ID 10, the system will automatically load and use this template.

  • For the list page of a specific category:You can name the template file as{模型table}/list-{分类id}.html. If you want to design a unique article list page for the category with ID5(such as the "Company News" category), you can name the template filearticle/list-5.html(assuming that the category belongs toarticleModel), the system will automatically apply this template to the article list of this category.

  • For a specific single page:You can name the template file aspage/{单页面id}.html. If you have an ID for3The "About Us" single page, you can create for itpage/3.htmltemplate file, the system will automatically apply it.

The advantage of this method lies in the fact that once the template file is named correctly and placed properly, the system can automatically recognize it, saving the steps of setting up individually in the background, especially suitable for batch or regular personalized needs.


II. Specify the template file manually through the background management

In addition to the automatically recognized naming conventions, AnQi CMS also provides flexible options to manually specify templates for specific content in the backend management interface.This is very useful for those who do not want to follow a fixed naming rule, or need to temporarily change the layout of a piece of content.

1. Customize the template for a specific article

When you edit an article, you can do so in the "Add Document" or "Edit Document" interface.“Other Parameters”Find in the collapsed item“Document Template”Field. Here you can enter the filename of the template you have designed for this specific article, for exampledownload.html.

This means, you can create a special for an article containing download linksdownload.htmlTemplate, to make it stand out from regular articles in layout, highlighting the download button or related instructions.Make sure that this template file exists in the currently enabled theme template directory, otherwise the article will not display correctly.

2. Customize templates for specific categories

In the "Content Management" module under the "Document Category" settings, when you edit a category, you will see in the“Other Parameters”part.Category TemplateField. This field allows you to specify a custom template for the list page or detail page of the current category, for examplespecial-list.html.

It is worth noting that the category template also provides aWhether to apply to subcategoriesThe option. If this is checked, all subcategories under the current category will inherit the custom template you set here.This greatly simplifies the work of unifying the layout for a series of related categories.

Moreover, there is also an additional category setting“Document Template”This field's purpose is to allow you to specify the categories under.to be displayedUse a custom template consistently. For example, if you have a 'Product Display' category, you can specify the 'Document Template' in its category settings.product_detail.htmlThen all product articles under this category will be displayed using this template, without the need to set it separately for each article.

3. Custom template for specific single page

In the 'Page Resources' module under 'Page Management', when editing a single page, you can findSingle page templateField. Here, you can fill in the name of the template file for the single-page design, for exampleabout-us.html.

This allows you to give important single pages such as "About Us" and "Contact Us" unique visual styles to suit their content features and marketing objectives.Similarly, make sure the template file you entered actually exists in the template directory of the current theme.


3. Basic Considerations for Template Design

Whether you choose to automatically recognize or manually specify a template, all custom template files should be stored in/templateUnder the currently enabled theme folder. The AnQi CMS template engine is similar to Django, using a concise and intuitive syntax:

  • Variable output:Using double curly braces{{ 变量名 }}to display data.
  • Logical Control:Use single curly braces and percentages{% 标签名 %}to handle conditional judgments (if), loops (for), introduce other templates (include) and template inheritance (extends) and so on.

When writing custom templates, you can fully utilizeincludeTag to introduce header, footer, sidebar, and other common code snippets to improve the maintainability and reusability of templates. At the same time, throughextendsThe label inherits a basic layout template, ensuring that the custom template maintains individuality while also keeping in line with the overall style of the website.Make sure to save your template file with UTF-8 encoding to avoid Chinese garbled characters.

Through the above two methods, Anqi CMS provides you with powerful template customization capabilities, whether it is fine-tuned to a single article or acts on the entire category, you can flexibly control and achieve truly personalized website layout.


Frequently Asked Questions (FAQ)

1. Why does the page still display the default style even though I have set a custom template for the article?Please first check that your custom template file is correctly placed in the currently enabled theme folder, and make sure that the filename matches the content you entered in the "Document Template" field in the backend (including the file extension).Secondly, the custom template may need to clear the system cache after it is set in the background, please try to manually clear the cache in the "Update Cache" feature of the background management interface.

2. What is the difference between "Category Template" and "Document Template" in the category settings? Do they affect each other?The "Category Template" mainly controls the page layout of the category itself, such as the style of the category article list page or the category detail page.And the 'document template' controls the layout of the detail pages for all articles in the category.They are independent settings but work together to display content under a category.If a category is set with both "category template" and "document template", then the "category template" only affects the category page, and the "document template" affects all article detail pages under the category.If the document template is specified separately, the settings of the article itself will be used preferentially.

3. If I create a template for a single page that conforms to the naming convention (for examplepage/3.html) and also manually specify a custom template (for exampleabout-us.html), which one will take effect?In most cases, manually specified custom templates take precedence over templates automatically identified by file naming conventions. When the system

Related articles

How to modularize the header, footer, and other common parts in a template and reference them on each page to display uniformly?

In website operation, maintaining the consistency and efficient management of the website pages is the key to improving user experience and operational efficiency.For AnQiCMS (AnQiCMS) users, modularizing the header, footer, navigation bar, and other common parts not only ensures consistency in the overall visual style of the website but also greatly simplifies the maintenance and update work in the future.Strong and flexible template system provided by AnqiCMS, allowing you to easily achieve this goal.### Understanding AnQiCMS Template Architecture AnQiCMS template files are usually stored in

2025-11-08

What page adaptation modes are supported by AnQiCMS templates, and how to select and implement responsive display?

In the multi-screen era, users access websites through various devices, which has become the norm.To ensure that the website can provide a smooth and friendly experience on any device, page adaptation has become an indispensable part of website construction.AnQiCMS (AnQi Content Management System) fully considers this requirement, providing a variety of flexible template adaptation modes to help users easily cope with display challenges on different devices.

2025-11-08

How to use Django template engine syntax to display variables and logic structures?

AnQiCMS (AnQiCMS) uses a template engine syntax similar to Django in template creation. This design philosophy aims to provide content operators and developers with a powerful and easy-to-use tool, allowing them to more flexibly control the display of website content.By mastering this template syntax, you can easily display dynamic data on the website front end and control the presentation logic of content based on specific conditions.### One, the core composition of template syntax: variables and logical structures The template syntax of AnQi CMS mainly consists of two major parts

2025-11-08

How to ensure that AnQiCMS template files are encoded in UTF-8 to avoid garbled page display?

During the process of building a website with AnQiCMS, you may occasionally encounter the situation where the displayed content is garbled, especially Chinese characters.This not only affects the aesthetics and user experience of the website, but may also have a negative impact on search engine optimization (SEO).The problem of garbled characters is usually related to the inconsistent encoding format of template files, and ensuring that AnQiCMS template files are saved in UTF-8 encoding is a key step to solving this problem.Why UTF-8 Encoding is Crucial?

2025-11-08

How to implement conditional (if/else) dynamic display of content and layout in a template?

In website operations and frontend development, we often need to flexibly display content or adjust the page layout according to different situations.This dynamic ability is the core value of the conditional judgment tag (`if/else`) in AnQiCMS templates.The Anqi CMS template engine is simple and powerful, allowing us to set logic on the page like writing program code, making the website content show endless possibilities.### The Dynamic Beauty of AnQi CMS Template

2025-11-08

How to loop through a list of data in a template and display it (using for loop), supporting counting and reversing?

In Anqi CMS template, efficiently displaying list data is an indispensable part of website content operation.Whether it is to display the latest articles, product lists, category directories, or customized data sets, flexible looping through these data and fine-grained control can greatly enhance the performance and user experience of the website.The Anqi CMS provides a powerful and easy-to-use template engine, its `for` loop tag is rich in features, supporting not only basic iteration but also easily implementing counting, reversal, and more advanced operations.### Core Concept: `for`

2025-11-08

How to avoid extra blank lines when template logical tags (such as if, for) are rendered on the page?

When developing templates in AnQiCMS, we often find that even though the template code itself looks neat, the final rendered HTML page may still contain some unexpected blank lines.These blank lines do not affect the page function, but may make the HTML source code look less tidy, and even in some extreme optimization scenarios, it may bring a slight increase in file size.For users who pursue code aesthetics and concise output, how to effectively avoid these redundant blank lines is a topic worth discussing.

2025-11-08

How to define and call the `macro` tag in AnQiCMS template to display reusable code blocks?

AnQiCMS provides a flexible and powerful template system, making the display of website content efficient and beautiful.In template development, in order to enhance the reusability and maintainability of code, we often encounter the need to encapsulate a commonly used code snippet so that it can be called in different places.This is when the `macro` tag becomes the key tool to achieve this goal.It allows us to define reusable code blocks, like functions in programming languages.Why do we need the `macro` tag?

2025-11-08