How to uniformly manage the alignment format of text in AnQiCMS multi-site templates?

Calendar 👁️ 75

In the multi-site environment of AnQiCMS, implementing unified management of text alignment formats across different sites is the key to enhancing brand consistency, optimizing user experience, and simplifying post-maintenance.}Although each site may have independent templates and content, we can certainly establish an efficient and unified alignment management strategy by巧妙ly utilizing the template mechanism and front-end technology of AnQiCMS.

AnQiCMS template mechanism and the foundation of unified management

AnQiCMS is renowned for its powerful multi-site management and flexible template customization capabilities. In the system architecture, all template files are uniformly stored in/templateUnder the directory, each site can have an independent template directory, for exampledefault/siteAAnd at the same time, static resources such as CSS, JavaScript, and images are usually placed in/public/static/Under the directory, for template reference.

Implement unified management of text alignment formats, the core lies in utilizing this layered structure. AnQiCMS uses syntax similar to Django template engine, supportingextends(Template inheritance) andinclude(Template reference) and other features, all of which are important tools for us to build a unified style basis.

The core strategy for unified text alignment format: CSS priority principle

The text alignment, such as left alignment, center alignment, right alignment, or both ends alignment, is essentially a presentation layer style of web content.**Practice is to delegate it to CSS (Cascading Style Sheets) for unified control, rather than manually setting it in each rich text editor.

Why emphasize CSS precedence? The reasons are as follows:

  1. Consistency guarantee:Through CSS, you can style text elements throughout the entire site or specific types of text elements (such as paragraphs<p>, headings<h1>-<h6>, lists<ul>Align rules once. Regardless of how the content changes, their alignment will remain consistent.
  2. Maintain efficiency:If in the future you need to adjust the alignment, you only need to modify one line of CSS code, and all affected sites and pages will be updated immediately, greatly reducing redundant labor.
  3. Avoid conflict and confusion:The alignment settings in a rich text editor are usually inline styles (inline style), which have a very high priority and are prone to overriding global styles, making it difficult to unify and debug styles.At the same time, it also makes the content tightly coupled with the presentation layer, which is not conducive to decoupling.
  4. Responsive design friendly:CSS can easily implement media queries, automatically adjust the text alignment according to the screen size of the device, and provide a **reading experience for different terminals.

Based on this, we recommend avoiding setting the text alignment format directly in the AnQiCMS backend rich text editor (such as in "Publish Document" or "Page Management"), and letting the global CSS take the lead.

Implement the steps for unified alignment management

  1. Create or identify a shared global CSS file:To ensure that all sites can share alignment rules, **the method is to create one or use a public CSS file that all site templates will load. You can choose to load it in/public/static/global/Create a file namedglobal.css.

  2. In the public header file (such asbash.html), include this CSS file:AnQiCMS templates usually have a common header file, such as one in the template directory underbash.htmlor a similar name. All page templates will go through{% extends 'bash.html' %}or{% include 'partial/header.html' %}It is introduced in this way. In this public header file, use<link>tag to introduce the one we createdglobal.css. AnQiCMS providessystemtag to get the base URL, convenient for cross-site references:

    <link rel="stylesheet" href="{{system.BaseUrl}}/public/static/global/global.css">
    

    Make sure this<link>tag is loaded before all other style sheets so that the site-specific CSS can override as needed.

  3. Inglobal.cssDefine global alignment rules:in thisglobal.cssIn the file, you can define uniform alignment rules for common text elements. For example:

    /* 全局默认左对齐 */
    body {
        font-family: 'PingFang SC', 'Helvetica Neue', Helvetica, 'microsoft yahei', Arial, sans-serif;
        line-height: 1.6;
        color: #333;
        text-align: left; /* 默认左对齐 */
    }
    
    /* 段落默认左对齐 */
    p {
        text-align: left;
        margin-bottom: 1em;
    }
    
    /* 标题居中 */
    h1, h2, h3, h4, h5, h6 {
        text-align: center;
        margin-top: 1.5em;
        margin-bottom: 1em;
    }
    
    /* 特定内容的居中(例如图片说明) */
    .caption {
        text-align: center;
        font-size: 0.9em;
        color: #666;
    }
    
    /* 如果有需要,可以为内容区定义两端对齐 */
    .article-content {
        text-align: justify;
    }
    

    You can choose different HTML tags or use class names (class) to finely control alignment according to your actual needs.

  4. (Optional) Implement site-specific fine-tuning and overrides:If

Related articles

Does AnQiCMS filter support custom non-space characters for `ljust` or `rjust` padding?

In the practice of content operation on AnQiCMS, we often need to do refined layout and design of text content on the page.For example, to maintain the alignment of tables or list items, we may use string padding functions, such as left-aligned padding (`ljust`) or right-aligned padding (`rjust`).A common question is, does AnQiCMS's template filter support using non-space characters to fill in the `ljust` or `rjust` operations?Today, let's delve deeply into this issue

2025-11-07

How to calculate the length of Chinese characters when using the AnQiCMS `center` filter to ensure centered effect?

In Anqi CMS template development, achieving accurate layout and beautiful typography is the key to improving user experience.Especially for text centering display, the `center` filter provides a very convenient feature.It can help us easily center a string within a specified length of space and fill in spaces on both sides to achieve the expected visual effect.Understand the working principle of the `center` filter This filter is designed ingeniously, it will automatically add spaces on both sides of the string according to the target total length

2025-11-07

How to dynamically adjust the center, left, and right alignment length of text in AnQiCMS?

In website content operation, the layout and alignment of content often directly affect the user's reading experience and the efficiency of information delivery.AnQiCMS as a flexible content management system not only provides basic alignment options in the background editor, but also provides powerful filter (Filters) functions at the template level, allowing you to dynamically and finely control the alignment and display length of text.### The dynamic alignment requirements beyond the editor In the AnQiCMS backend content editor, we can of course directly set the alignment of the text to center, left, or right

2025-11-07

What is the default character used for filling by the `center`, `ljust`, and `rjust` filters in the AnQiCMS template?

The AnQiCMS template system provides a rich set of filters (filters) to help us format and process content.When performing text alignment operations, the `center`, `ljust`, and `rjust` filters are commonly used tools.They can center, left-align, or right-align our text content within a fixed width.When first encountering these filters, many users may be curious about what characters the system will use to fill in the blank areas when the text length is insufficient for the specified width? Below

2025-11-07

How to truncate the article abstract to a fixed number of characters and automatically add an ellipsis at the end in AnQiCMS?

In website operations, how to effectively and beautifully display article lists or cards while avoiding excessive space occupied by long content is a common challenge.Especially on the homepage, category page, or search results page, we often need to extract part of the article content as a summary and elegantly add an ellipsis at the end to guide visitors to click and view the details.AnQiCMS fully considers the needs of content operators, making this operation very simple and intuitive through flexible template tags and powerful filters.How does AnQiCMS handle the article abstract content?

2025-11-07

How to extract HTML content (such as rich text fields) in AnQiCMS templates while maintaining the integrity of the tag structure?

In AnQiCMS templates, when handling content display, it is often necessary to truncate rich text fields (such as article details, product descriptions, etc.).Directly extracting strings from HTML content often leads to the destruction of tag structure, which can affect page layout and even cause rendering errors.幸运的是,AnQiCMS提供了一些非常实用的模板过滤器,可以帮助我们优雅地完成这项任务,同时确保HTML标签的完整性。

2025-11-07

How to accurately calculate the length of a string containing Chinese, English, and special characters using the AnQiCMS `length` filter?

In website content management, the precise control of string length is a seemingly trivial but crucial aspect.It not only affects the display beauty of the content, but also directly relates to the search engine optimization (SEO) effect and user experience.For users of AnQiCMS, the flexible and powerful template engine provides a variety of tools to meet such needs, among which the `length` filter is a powerful assistant for calculating string length.

2025-11-07

In AnQiCMS template, how to truncate article titles by word and display an ellipsis to adapt to different layouts?

In modern web design, the flexibility of content display is crucial, especially for core elements like article titles.When the article title is too long and our layout space is limited, how to elegantly truncate the title and add an ellipsis so that it maintains readability and adapts to different devices and layouts is a problem often encountered in the development of AnQiCMS templates.Luckyly, AnQiCMS's powerful template engine provides a simple and efficient solution.

2025-11-07