How to create a custom template for AnQiCMS website to achieve personalized display?

Calendar 👁️ 59

AnQiCMS with its flexible and efficient features provides a wide space for personalized display of website content.If you want your website to have a unique appearance and features, creating a custom template is undoubtedly **the way**.By deeply customizing the template, you can fully control every detail of the website, from brand image to user experience, achieving a high degree of personalization, and standing out among many websites.

This article will guide you to understand how to create and apply custom templates in AnQiCMS, helping you turn your design concepts into reality and realize the personalized display of the website.


The foundation of template customization: Understand AnQiCMS template mechanism

In AnQiCMS, the core of template customization lies in understanding its template engine based on the Go language, which borrows syntax similar to Django templates, making it easy for users familiar with web development to quickly get started.

First, the template files should be used uniformly.htmlas suffixes, and stored centrally in the root directory of the website/templateIn the folder. Resources such as stylesheets, JavaScript scripts, and images related to the template should be placed separately in/public/static/Under the directory. This separation helps keep the template files neat and convenient for managing static resources.

AnQiCMS's template syntax is concise and powerful:

  • Variable outputUse double curly braces{{变量名}}to display data, for example{{archive.Title}}can display article titles.
  • Logical controlUse single curly braces and percent signs{% 标签 %}Perform logical operations, such as conditional judgments{% if 条件 %}Loop traversal, such as{% for item in 列表 %}All logical tags need corresponding end tags, for example{% endif %}or{% endfor %}.
  • Variable naming: To maintain consistency, the variable names in the template usually adopt camel case naming rules, that is, the first letter of each word is capitalized (such asarchive.Id,archive.Title)
  • Coding specificationsAll template files should be encoded in UTF-8 to avoid garbled text on the page.

Each custom template should contain one in its root directory.config.jsonA file used to describe the basic information of a template, such as template name, package name, version, author, etc. among which,template_typeThe field is particularly important, it defines the adaptation type of the template (0 for adaptive, 1 for code adaptation, 2 for independent computer + mobile), which determines how your website responds to visits from different devices.


Step 2: Create your first custom template

Creating a custom template is a systematic process, every step from planning to writing the specific files is crucial.

1. Planning and Preparation

Before starting to write code, it is recommended that you first clarify the display requirements of the website:

  • Website TypeIs it a corporate website, a product showcase, or a blog?
  • Adaptation MethodDo you need responsive design (adaptive), provide different code (code adaptation) for different devices, or deploy independent templates for PC and mobile separately?
  • Page structure:What core pages are included on the website (home page, article list, detail, single page, etc.), as well as their approximate layout.

According to your plan,/templateCreate a new folder under the directory as your template directory, for examplemy_custom_theme. Then, create a file in this new folderconfig.jsonand fill in the relevant information.

2. Core page template setup

AnQiCMS supports two template file organization modes: folder organization mode and flattened file organization mode. Regardless of which one you choose, here are some naming rules for template files of core pages:

  • Public code snippetsTo avoid code repetition, you can split the header, footer, sidebar, and other common parts into independent files, for examplepartial/header.html/partial/footer.html. These files can be referenced by{% include "partial/header.html" %}tags in other templates.
  • Basic Skeleton: Create abase.htmlfile as the basic skeleton for all pages. In this file, define the basic structure of the HTML document (<html>,<head>,<body>) as well as common styles and script references. Use{% block 区域名称 %}{% endblock %}tags to define content areas that can be rewritten or extended by child templates. For example, you can define{% block title %}/{% block content %}etc.
  • Home:index/index.html(folder mode) orindex.html(Flat mode). This is the entry page of the website, which usually displays the latest articles, recommended content, carousel images, etc.
  • Model list page: For example, the article list pagearticle/list.htmlorarticle_list.html, Product list pageproduct/list.htmlorproduct_list.htmlThese pages are used to display a list of specific content models.
  • Model detail pageFor example, article detail pagearticle/detail.htmlorarticle_detail.htmlProduct detail pageproduct/detail.htmlorproduct_detail.htmlThese pages are used to display the detailed content of a single article or product.
  • single page:page/detail.htmlorpage_detail.htmlSuitable for static content pages such as 'About Us' and 'Contact Us'.
  • Mobile end templateIf yourtemplate_typeSet to 1 or 2, you need to create a subdirectory in the template directorymobile/and create a mobile adaptation template file with the same structure within it.

Reference static resourcesIn your template file, when referencing CSS, JavaScript files or images, you should use the AnQiCMS provided{templateUrl}Variables are used to construct the correct path. For example:<link href="{% system with name="TemplateUrl" %}/css/style.css" rel="stylesheet"> <img src="{% system with name="TemplateUrl" %}/images/logo.png" alt="Logo"> {% system with name="TemplateUrl" %}It will automatically be replaced with the root path of the static resources of the current template, ensuring that the resources can be loaded correctly.


Chapter 3, Flexible Use of AnQiCMS Template Tags and Filters

AnQiCMS provides rich template tags and filters, allowing you to easily retrieve and process various data.

1. Data acquisition and display

  • Site global information: Use.{% system with name="字段名称" %}Label to obtain website name, Logo, filing number, basic URL, etc.
  • Contact Information: Pass{% contact with name="字段名称" %}Label to obtain backend configured contact, phone, email, social media links, etc.
  • Navigation list:{% navList navs %}Used to retrieve website navigation menu data, supporting multi-level menus and custom navigation categories.
  • Categories and documents:
    • {% categoryList categories %}: Retrieve article or product category list.
    • {% archiveList archives %}: Retrieve a list of articles or product documents, supporting multiple conditions such as category, model, recommended attributes, sorting methods, and pagination functionality.
    • {% pageList pages %}: Retrieve a single-page list.
    • {% archiveDetail with name="字段名称" %}Get detailed information of the current document on the detail page (such as title, content, images, custom fields, etc).
    • {% pageDetail with name="字段名称" %}Get detailed information of a single page.
  • Model custom fieldsIf your content model defines additional fields, you can usearchiveDetailorcategoryDetail

Related articles

How to call and display the Banner image of the AnQiCMS category page

In website operation, the category page is not only the display of content classification, but also a key entry for users to explore the website and gain a deeper understanding of products or services.A well-designed category banner image that can effectively enhance the visual appeal of the page, strengthen the brand image, and guide users to the next step of operation.AnQiCMS as an efficient content management system, provides a flexible way to manage and call these banner images. We will delve into how to set up a Banner image for category pages in AnQiCMS and display it on the website frontend.###

2025-11-08

How to obtain and display the detailed description information of AnQiCMS categories?

In website operation, clear and detailed classification descriptions are crucial for user experience and search engine optimization.AnQiCMS as a powerful content management system provides a flexible way to manage and display these category information.This article will delve into how to retrieve and effectively display detailed category descriptions on the frontend page in AnQiCMS.

2025-11-08

How to implement nested display of multi-level categories in AnQiCMS navigation menu?

In website construction, a clear and easy-to-use navigation menu is crucial for improving user experience and the overall structure of the website.AnQiCMS provides flexible settings for managing the navigation menu, allowing users to easily implement nested hierarchical classification display, thereby better organizing website content and guiding visitors to explore.To implement multi-level nested navigation, we mainly complete it through the "Navigation Settings" function in the AnQi CMS backend.This feature is located in the "Background Settings" area, it can not only manage the top navigation of the website, but also create various custom navigations as needed

2025-11-08

How to display the subcategory list under the AnQiCMS category page?

In AnQiCMS, you can easily display the subcategory list under the category page with flexible template tags.This is crucial for building a clear website structure, improving user navigation experience, and optimizing search engine crawling efficiency.AnQiCMS powerful template system and its Django-style tag syntax make the display of such dynamic content intuitive and efficient.To implement displaying the subcategory list under the category page, the following steps are mainly involved:

2025-11-08

What template types does AnQiCMS support, and how do you choose the most suitable display mode for the website (adaptive, code adaptation, PC + mobile end)?

AnQiCMS as an efficient and customizable content management system provides a variety of flexible modes for displaying website content to meet the diverse needs of different users.Understanding these template types and their applicable scenarios is crucial for building a website with a good user experience, easy management, and search engine optimization.AnQiCMS provides three main template types for users to meet the display needs of different websites.They are adaptive templates, code adaptation templates, and independent PC + mobile site templates.Each pattern has its unique characteristics and applicable scenarios

2025-11-08

How to correctly call and display the title and content of the article in the template?

When using AnQiCMS to build and manage websites, the title and content of articles are core elements. Their correct invocation and display are directly related to the visual presentation, user experience, and search engine optimization of the website.Understanding how to efficiently and accurately handle this information in the AnQiCMS template is the key to website content operation and template customization.AnQiCMS's template system adopts syntax similar to the Django template engine, which provides great flexibility and customizability for content display.In the template, you will find that variables are usually enclosed in double curly braces

2025-11-08

How to utilize the flexible content model of AnQiCMS to customize unique display fields for different types of content (such as articles, products)?

AnQiCMS, this is a content management system driven by the Go language, which performs very well in content management, especially its flexible content model function.As website operators, we often need to publish various types of content, such as detailed product introductions, professional technical articles, vivid case studies, and so on.Each content has its unique display requirements and information structure.Traditional content management systems may require cumbersome secondary development to meet these differences, but AnQiCMS's flexible content model is exactly born to solve this pain point, allowing us to easily customize

2025-11-08

How does AnQiCMS implement the switching and display of multilingual content to enhance the international user experience?

In today's globalized digital world, a website that can present its content in multiple languages undoubtedly can greatly expand its user base and significantly enhance the user experience.AnQiCMS as a powerful content management system, fully considers the needs of international operation, and provides a flexible and efficient mechanism to switch and display multilingual content.### Why is multilingual content so important? Imagine a user from Japan visiting your website. If they can read product descriptions or service instructions in their native language, their trust and engagement will immediately increase

2025-11-08