As an experienced website operations expert, I know that the flexibility and customizability of a content management system (CMS) are crucial for the long-term development of the website and the user experience.AnQiCMS (AnQiCMS) provides an excellent solution in this aspect with its powerful functions and ease of use.Today, let's delve into how to set up custom templates for your document detail page or category list page in AnQiCMS, making your website content display more personalized and professional.

In AnQiCMS, the flexibility of content display is one of its core advantages.Whether it is articles, products, or any other custom content model, AnQiCMS allows you to break away from the monotonous default layout, and create a unique page style according to your brand tone, content characteristics, or user needs.This not only helps to enhance the user experience, but also strengthens the brand image through differentiated display, and even has a positive impact on SEO optimization.

The Anqi CMS template system uses a syntax similar to the Django template engine, which is very easy to get started with for those familiar with web development. Even those who are not very familiar with technology can achieve template switching and configuration through intuitive backend operations. All template files are stored in a unified location./templateIn the corresponding template folder created under the root directory, while style sheets, JavaScript scripts, and images, etc., are stored independently./public/static/The catalog, this separation design makes the template structure clear and more convenient to maintain.

Next, we will explain in detail in two main ways how to set up a custom template for you.

Method 1: By naming conventions, let AnQiCMS automatically recognize and apply the template

AnQi CMS provides an intelligent and convenient mechanism that allows you to automatically identify and apply custom templates by using specific template file naming rules, without the need for additional settings in the background.This approach is particularly suitable for scenarios where unique layouts need to be applied to specific content or categories.

  1. Set an independent template for a single document detail page:When you want a specific article, product, or other type of document to have a completely independent detail page layout, you can follow the{模型table}/{文档id}.htmlFormat the name of your template file. For example, if your document model table name isarticle(article), and you want to set ID for123Set the article to customize the template, then you can create it in your template folder (such as/template/default/) under createarticle/123.htmlThis file. When the user accesses this article with ID 123, the system will automatically load and use it.article/123.htmlThe layout of the layout. This fine-grained control allows you to provide exclusive display for key content on the website.

  2. Set an independent template for a single category list page:Similarly, if you want a specific content category (such as a product series or a type of news) to have a unique list display page, you can follow{模型table}/list-{分类id}.htmlFormat the template file name. For example, forarticle(Article) The ID in the model is45category, you can createarticle/list-45.htmlThis file. In this way, when the user visits the article category page with ID 45, the system will enable this custom list template.

It is worth mentioning that, in addition to naming by ID, AnQi CMS also supports more general model-level templates, such as{模型table}/detail.htmlwhich are used for the default detail pages of all documents for the model, as well as{模型table}/list.htmlThis is the default list page for all categories of the model. These are basic templates that you can customize with more refined IDs or filenames.

Method two: Specify template files flexibly through the backend management interface

In addition to the naming conventions, Anqi CMS also gives you the ability to fine-tune control in the backend management interface.This method is more suitable for those who want to manually specify the template or do not want the template name to be strongly bound to the specific ID.

  1. Specify a template for a single document detail page:When editing documents, you can enterContent Management -> Document ManagementFind the corresponding document and click edit.In the 'Other Parameters' section of the document editing interface, you will find an input box named 'Document Template'.download.html(If you havearticlecreated adownload.htmlfile to display download-type documents). Make sure that the template file path you enter is relative to your current template folder (for example/template/default/article/The valid path. The system will prioritize the template specified here.

  2. Specify the template for the category list page:For the category list page, you can inContent management -> Document classificationEdit the corresponding category.In the 'Other Parameters' section of the category editing page, you will see a 'Category Template' field.custom_list.html. Similarly, this path is relative to the current template folder under the model directory (for example/template/default/article/The relative path. It is especially noteworthy that in the category settings, there is also a "Document Template" field. The purpose of this field is to, for the category underAll documentsSpecify a unified detail page template. For example, if you have a product category and you want all products in that category to use a template namedproduct_detail_standard.htmlThe template, you can fill in this field to avoid the trouble of setting it one by one.

Tips in practice

  • Template file storage:All custom templates should be placed in the theme you are currently using./template/{您的主题文件夹名}/Under the directory. For example, if you are using the default theme namedefault, and inarticlethe model, then the file path is usually/template/default/article/detail.htmlor/template/default/article/123.html.
  • Using existing tags:In the custom template, you can fully utilize the various template tags provided by AnQi CMS (such as{% archiveDetail %}Get document details,{% categoryDetail %}Get category details,{% archiveList %}Get document list and so on), these tags can help you easily call and display the content data of the background management.
  • File encoding:No matter which operating system you edit the template file under, please be sure to save it in UTF-8 encoding format to avoid garbled text on the page.
  • Test and debug:Before deploying to the production environment, it is strongly recommended that you thoroughly test your custom template in the development environment to ensure that all features work properly and the layout is displayed correctly.The Anqi CMS usually provides error tips when template parsing fails, which helps with debugging.

Through the above two methods, AnQiCMS provides the ability to customize templates from global defaults, model generics to fine-grained control of individual content, allowing you to flexibly create websites that meet your actual operational needs and have excellent brand image and user experience.


Frequently Asked Questions (FAQ)

  1. Q: Where should I place my custom template file so that AnQiCMS can recognize it?A: Your custom template file should be placed in/template/{您的主题文件夹名}/{模型table}/In the directory. For example, if you are using a nameddefaulttopic, and you want to set up a detail page template for the article (model table isarticle), then the file path might be/template/default/article/detail.htmlOr/template/default/article/123.html(If it is for a specific article with ID 123). For the category list page template, it is usually/template/default/article/list.htmlor/template/default/article/list-45.html.

  2. Q: Why does the document detail page still display the default style, even though I have only set the 'Category Template' for a certain category?A: "Category template" is mainly used to change the category'slist pagedisplay style. If you want to display the category underDocument detail pageAlso use a specific template, you need to find the "Document Template" field on the edit page of this category, and fill in the filename of the template you want to use on the document detail page.These are two different settings that control the list page and the detail page of the documents below.

  3. **Q: If I created a template file with a specific ID (such asarticle/123.html), as well as in the background document editing page's