How to customize templates in AnQiCMS to change the overall visual style and layout of the website?

Calendar 👁️ 71

In today's era, where brand and user experience are emphasized, the visual style and layout of a website are key to its successful operation.AnQiCMS (AnQiCMS) fully understands this point, therefore it provides highly flexible template customization features, allowing users without a strong development background to create personalized websites according to their unique needs.

If you are considering changing the overall style of the website or designing a dedicated layout for specific content, it will be very helpful to understand how to customize templates in AnQiCMS.This can make your website stand out among many competitors, and it can effectively improve user experience, conveying unique brand information.

Understand the template mechanism of AnQiCMS

The Anqi CMS template system is designed to be quite intuitive and efficient, it uses syntax similar to the Django template engine, which is very easy to get started with for users familiar with web development.

First, all template files are uniformly stored in the root directory of the site/templateIn the folder. Each independent template needs to have its own subfolder in this directory.The static resources such as images, CSS styles, JavaScript scripts, and so on required by the template will be placed in one place/public/static/directory.

In the template files, you will find two main syntax structures:

  • Variable output: Using double curly braces{{变量}}To display data, such as article titles{{archive.Title}}.
  • Logical controlUse single curly braces and percentages{% 标签 %}To implement conditional judgment (such asif), Loop traversal (such asfor)Complex logic. Such tags usually require a corresponding closing tag (for example{% endif %}or{% endfor %})to complete a code block.

In addition, to ensure the correct display of website content, all template files should be encoded in UTF-8 format.

Create and activate your custom template

The best way to start customizing a template is to start from an existing template (such as the default system template).

  1. Copy an existing template: Enter/templateDirectory, find a template folder that is close to your needs (for exampledefault), then make a complete copy of it and name the new folder something distinctive, likemy_custom_theme.
  2. Configurationconfig.json: Enter the newly createdmy_custom_themefolder, and you will see aconfig.jsonFile. This file is the 'ID card' of the template, telling AnQiCMS about the basic information of this template. You need to edit it, focusing on the following fields:
    • "name"Template display name, for example"我的定制主题".
    • "package"Template identifier, usually consistent with your folder name, for example"my_custom_theme". The name can only contain letters and numbers.
    • "template_type"This determines how your website adapts to different devices. You can choose0Adaptive template (a set of templates that adapt to all devices),1represents code adaptation (providing different HTML on the server side based on the device type), or2represents a computer + mobile independent template (a separate mobile template needs to be made).
    • "status": Used to indicate that the template is in use,0is disabled,1is in use. Please note that only one template can be used at a time.statusWith1However, you can also switch templates directly in the background, and the system will automatically update this status.
  3. Activate in the background: Completeconfig.jsonAfter modification, log in to the AnQiCMS backend, find the "Template Design" menu under "Website Template Management".Here, you should see the new template you just created. Click the 'Enable' button next to it, and your website's front end will immediately switch to this new template.

Explore the directory structure of the template files

AnQiCMS's template file organization is very flexible, you can use folder mode or flattened mode to manage your template files.Regardless of which, there is a set of default naming conventions that allow the system to automatically recognize and apply the corresponding template.

Common template files and directories include:

  • bash.html: Used to store the common parts of a website, such as the header (head), footer (footer) and other code.
  • partial/The directory: stores some reusable code snippets, such as sidebars, breadcrumb navigation, etc., through{% include "partial/sidebar.html" %}such tags can be introduced.
  • index/index.htmlorindex.htmlThis is the home page template of the website.
  • {模型table}/index.htmlor{模型table}_index.htmlThe list page or home page of a specific content model (such as an article, product).
  • {模型table}/detail.htmlor{模型table}_detail.htmlThe detail page of a specific content model. For example, an article detail page might be.article/detail.html.
  • {模型table}/list.htmlor{模型table}_list.html: List page under a specific content model category.
  • page/detail.htmlorpage.html: Single page detail page, such as 'About Us', 'Contact Us', etc.
  • mobile/Directory: If you have chosen the "Code Adaptation" or "PC+Mobile Independent Site" mode, all the template files corresponding to the mobile end will be stored here, with a structure similar to the PC template.

It is worth mentioning that AnQiCMS also supports more refined template customization. For example, you can create a dedicated template for documents, categories, or single pages with specific IDs, named in a manner like{模型table}/{文档id}.html/{模型table}/list-{分类id}.htmlorpage/{单页面id}.html. When publishing content in the background, you can also specify the custom template filename to be used.

Use AnQiCMS tags to make content lively.

The core of the template lies in dynamically displaying website content and configuration information through tags and variables.AnQiCMS provides rich built-in tags, which are powerful tools for building dynamic websites.

  1. Get global information of the website

    • {% system with name="SiteName" %}: Easily obtain the website name, Logo, filing number, copyright information, etc., which are usually used in the header or footer.
    • {% contact with name="Cellphone" %}Display the website's contact phone number, address, email, social media accounts, etc., for easy user contact.
    • {% tdk with name="Title" %}To generate dynamic SEO titles, keywords, and descriptions for a page is crucial for search engine optimization. For example, by{% tdk with name="Title" siteName=true %}The current page title can be combined with the website name to display.
  2. Build flexible navigation and structure

    • {% navList navs %}: Retrieve and display the website's navigation menu, supporting multi-level navigation. You can useforLoop throughnavsvariables to build your menu structure, by{{item.Link}}and{{item.Title}}generating navigation links.
    • {% breadcrumb crumbs %}Generate the breadcrumb navigation of the website, enhance user experience and clarity of website structure.
  3. Dynamic content display

    • {% archiveList archives with type="page" categoryId="1" limit="10" %}: Retrieve article or product list. This is one of the most commonly used tags, and you can filter content based on categories, models, recommended attributes, sorting methods, and other conditions. Whentype="page"you can combine with{% pagination pages %}Tags implement pagination functionality.
    • {% archiveDetail with name="Title" %}In the detail page, directly obtain the detailed information of the current article or product, such as title, content, thumbnail, publication time, etc. For the content fieldContentIt usually needs to be added|safeFilter{{archiveContent|safe}}to ensure that the HTML code is parsed correctly and not displayed as escaped.
    • {% pageList pages %}and{% pageDetail with name="Title" %}are used to get the list of single pages and the details of a single page, usage is similar toarchiveList/archiveDetailSimilar.
  4. Implement advanced logic and code reuse

    • {% if 条件 %} ... {% elif 其他条件 %} ... {% else %} ... {% endif %}: Perform conditional judgment, displaying different content based on different situations.
    • {% for item in 列表 %} ... {% endfor %}: Loop through arrays or lists to dynamically generate repeated content blocks.
    • {% include "partial/header.html" %}: Introduce other template files to achieve code reuse and make the template structure clearer. You can also pass specific variables to the imported template bywithPass parameters to the imported template to pass specific variables.
    • `{%

Related articles

How to manage custom fields in the content model of AnQiCMS and call them to display on the front-end page?

AnQi CMS is an efficient and customizable enterprise-level content management system, one of its core highlights is the 'flexible content model'.This feature greatly expands the management boundaries of website content, allowing us to create various and unique content structures according to actual business needs.Among these, custom fields (or custom parameters) play a crucial role, allowing our website content to go beyond traditional article titles, body, and summaries, and carry more personalized information, ultimately displaying flexibly on the front-end page.

2025-11-07

How to configure Docker reverse proxy to display multiple independent websites for AnQiCMS multi-site feature?

AnQiCMS (AnQiCMS) is favored by many website operators for its efficient and flexible content management capabilities.Especially its powerful multi-site management feature, combined with Docker containerization technology and reverse proxy, allows you to easily set up and manage multiple independent websites on the same server, greatly enhancing operational efficiency and reducing maintenance costs. ### Discover the charm of multiple sites Imagine that you may have several different brands, aimed at different audiences, or serving different regions, but their content update and management processes are roughly the same.

2025-11-07

How to automatically convert URLs to clickable links in AnQiCMS templates using the `urlize` filter?

In website content management, we often need to display external links in articles, comments, or introductions.Manually adding the `<a>` tag to each URL is not only cumbersome but also prone to errors, especially when dealing with large amounts of user-generated content or importing data from other sources.Fortunately, AnQiCMS provides a very practical template filter——`urlize`, which can automatically identify URLs and email addresses in text and convert them into clickable links, greatly simplifying the work of content managers.

2025-11-07

How to set the website logo and filing number of AnQiCMS so that it can be displayed correctly on the front-end page?

During the process of building a website, the brand identity (Logo) and the necessary compliance information (record number) are indispensable elements.They can not only enhance the professionalism and credibility of the website, but also provide clear guidance to users.AnQiCMS is an efficient content management system that provides an intuitive and convenient way to set these information and ensures that they are displayed correctly on the website front-end page. Next, we will learn how to set the website logo and filing number in AnQiCMS in detail.

2025-11-07

Where should the AnQiCMS template files be stored, and what file extensions are supported?

AnQiCMS is designed very clearly and flexibly in template file management, aiming to allow users to customize the appearance and functions of the website efficiently.If you are using AnQiCMS to build or maintain a website, understanding the location of template files and supported suffixes is the foundation for front-end development and customization.

2025-11-07

How to use Django template engine syntax to efficiently display various dynamic content in AnQiCMS?

In AnQi CMS, you will find that the built-in Django template engine syntax is an extremely powerful and flexible tool, which can help you efficiently convert backend data into dynamic and lively content on the frontend page.Master this syntax, and you'll not only be able to display basic text and images, but also build complex, interactive dynamic pages, making your website vibrant.The template syntax design of Anqi CMS is very intuitive, it draws on the characteristics of the Django template engine and integrates the concise and efficient Go language.

2025-11-07

How to use `if-else` conditional tags to control the display logic of content in AnQiCMS templates?

In AnQiCMS templates, make good use of the `if-else` conditional judgment tag to make content display more intelligent In website content operation, we often need to display different content or styles according to different conditions.For example, when the article list is empty, display 'No content', when an article is in the recommended state, add a 'HOT' mark, or add a special style to the first item in the loop.

2025-11-07

How to use the `for` loop tag to iterate and display list data in AnQiCMS template?

In AnQiCMS templates, dynamically displaying list data is one of the core operations for building rich website content.Whether it is displaying the latest articles, hot products, category lists, or any custom content collection, the `for` loop tag is your helpful assistant.It allows you to easily traverse data and customize the display of each item according to your needs.Understanding the basics of the `for` loop tag The `for` loop tag is a control structure in the AnQiCMS template engine used for iterating over collection data.

2025-11-07