How to create a responsive, code adaptation, or PC+mobile separation template for the AnQiCMS website?

Calendar 👁️ 72

As an expert in AnQiCMS operation, I know that a high-quality template is crucial for the attractiveness and user retention of a website.AnQiCMS provides great flexibility in template design, supporting multiple modes to meet different business needs and user access habits.I will elaborate in detail on how to create adaptive, code adaptation, or PC+mobile terminal separation templates for the AnQiCMS website.

AnQiCMS template development basics

Before delving into different template patterns, we first understand some common rules for AnQiCMS template creation. AnQiCMS template files are uniformly used.htmlsuffix and stored in/templatein a folder named after each template independently located in the directory. For example, you created a folder namedmythemethat contains all the files of the template named/template/mytheme/. The CSS styles, JavaScript scripts, images, and other static resources required by the template should be stored in/public/static/the directory to ensure efficient loading and management.

AnQiCMS template engine syntax is similar to Django, variables are passed through double curly braces{{变量名}}To refer to, while conditional judgments and loop control logic tags use single curly braces and percent signs{% 标签 %}Define, and end it with the corresponding closing tag. This concise and intuitive syntax makes it easy to create and modify templates.

The core of each template is the directory under its root.config.jsonThe configuration file. This file defines the name, version, author, and other basic information of the template, among which the most critical field istemplate_typewhich determines the responsive mode that the template will adopt:0Represents adaptive,1Represents code adaptation,2Represents PC + mobile separation. Understand and configure correctlytemplate_typeIs the first step in building different types of templates.

AnQiCMS encourages modular template development. You can{% include "partial/header.html" %}use tags to introduce common code snippets, such as headers, footers, or sidebars, to avoid repetition.{% extends 'base.html' %}Tags allow you to create a basic skeleton template, other pages can inherit this skeleton, rewriting only specific content blocks, greatly improving the maintainability and development efficiency of the template.

AnQiCMS three template modes explained

AnQiCMS offers three template modes, designed to meet diverse needs from single responsive design to fully independent dual sites.

1. Adaptive Template

Adaptive mode is the most common responsive design method, which serves all devices through a complete set of template code. In this mode, you areconfig.jsonset"template_type": 0.

The core idea is to use front-end technologies such as CSS media queries (Media Queries), Flexbox, and Grid layout (Grid) to automatically adjust web content and layout according to the screen size, resolution, and orientation of the user's device.For example, on a wide-screen monitor, content may be presented in a multi-column layout, while on a mobile screen it automatically converts to a single-column stack.

Create an adaptive template, be sure to put it on the page.<head>the tag with<meta name="viewport" content="width=device-width, initial-scale=1.0">To ensure that the browser correctly renders the viewport.The advantage of this pattern lies in the low maintenance cost, as you only need to manage a set of code; at the same time, since all devices access the same URL, this is also very beneficial for search engine optimization (SEO), avoiding potential duplicate content issues.For most small and medium-sized enterprises and self-media operators, adaptive templates are usually a balance point between performance and maintenance costs.

2. Code-adaptive Template

The code adaptation mode provides a more refined way to customize the device experience while still maintaining a unified URL structure. In this mode,config.jsonof"template_type"should be set to1.

In the code adaptation mode, AnQiCMS will dynamically select the corresponding template file for PC or mobile end based on the type of device accessed by the user (detected through User-Agent).This means that, although users on the PC and mobile ends access the same URL, the content they see and experience may be completely different because AnQiCMS loads different templates optimized for their devices.

To implement code adaptation, you need to create a folder named in your template folder.mobile/in your template folder. Thismobile/The directory will specifically store the template files for the mobile version, and the internal directory structure and file naming should be consistent with the PC template. For example, if your PC homepage template isindex/index.htmlThen the corresponding mobile homepage template should bemobile/index/index.htmlIfmobile/A template file for a missing page under the directory is missing, the system usually tries to backtrack and use the PC template, but in order to ensure a consistent mobile experience, it is recommended to create a corresponding mobile template for all pages that need customization.

Related articles

What character encoding format should the AnQiCMS template file follow when editing?

As an experienced website operator who deeply understands the operation of AnQiCMS, I know that the details of content presentation are crucial to user experience.The character encoding of the template file is one of the essential basic links that should not be ignored.Clear and accurately displaying content is the first step to attracting and retaining users. ### AnQiCMS Template File Character Encoding Specification AnQiCMS template files must strictly follow the UTF-8 character encoding format when edited and saved.

2025-11-06

How to write conditional judgment (if/else) and loop (for) logic tags in AnQiCMS templates?

As a professional who deeply understands the operation of AnQiCMS, I know that template design plays a core role in the presentation of website content.By flexibly using conditional judgment and loop logic, we can transform static template files into dynamic and intelligent content display platforms, thus better meeting user needs and enhancing the interactivity and user experience of the website.This article will discuss in detail how to write conditional judgment (`if/else`) and loop (`for`) logic tags in AnQiCMS templates, helping you create a more expressive website.

2025-11-06

How to properly define and use variables in the AnQiCMS template?

As an experienced security CMS website operation person, I know that high-quality and clear content is the key to attracting and retaining users.In AnQiCMS template development, correctly defining and using variables is the foundation for dynamic content display and improving user experience.Below, I will elaborate on how to define and use variables in AnQiCMS templates, to help you better master content display.

2025-11-06

How should static resources (CSS/JS/images) be stored and referenced in the AnQiCMS template?

As a website manager who is deeply familiar with AnQiCMS operation, I know that proper management of website static resources is crucial for improving user experience and website performance.In AnQiCMS template development and maintenance, reasonably storing and referencing CSS, JavaScript, and images, etc., is the foundation for building an efficient and stable website.Below, I will elaborate on this key link.

2025-11-06

How to set up an independent directory structure for the mobile template of AnQiCMS?

As a website operator who is deeply familiar with the operation of AnQiCMS, I know that a flexible and efficient template management mechanism is important for the website, especially in the mobile-first era, providing an independent optimized template experience for mobile devices is the key to attracting and retaining users.AnQiCMS provides powerful support in template design, including setting up a separate directory structure for mobile templates, which allows us to provide customized content display and interactive experience for different devices.

2025-11-06

Where is the root directory of AnQiCMS template located?

As a senior security CMS website operator, I fully understand the core position of templates in website construction and content presentation.The template not only determines the visual style of the website, but also directly affects user experience and the efficiency of content delivery.Accurately understand the storage location of the template file is the basis for carrying out any website customization and optimization work. ### The Root Directory Location of AnqiCMS Templates In the architecture design of AnqiCMS, all the core files of the website templates are stored in a clear root directory.

2025-11-06

When creating a new template, what are the required and optional fields in the `config.` file?

In Anqi CMS, creating a new website template is a key step to achieving personalized content display.The core of each template includes a `config.` configuration file, which is like the template's 'ID card', declaring the basic information, functional characteristics, and management status to the system.Familiarize yourself with the structure and field functions of the `config.` file, which is crucial for website operators and template developers, as it ensures that the template is correctly identified, managed, and applied by the system.

2025-11-06

How to configure the display mode of the `template_type` field in `config.`?

As an experienced CMS website operation personnel, I am well aware of the importance of template configuration for website presentation and user experience.Today, let's delve into the `template_type` field in the `config.` file, which finely controls the display mode of your website template.In AnQi CMS, each template package core includes a configuration file named `config.`.This file is the 'identity certificate' of the template, which defines the name, version, author, and other basic information of the template. Among them

2025-11-06