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