In the rapidly developing multi-site ecosystem of Anqi CMS, efficiency and consistency have always been the focus of operators.For enterprises managing multiple brand sites, sub-sites, or content branches, it is undoubtedly a great challenge to ensure content uniqueness and brand tone while avoiding duplicate labor, ensuring unified management of public modules, and quick updates. 幸运的是,AnQi CMS provided a powerful and flexible solution, which is an indispensable part of the template engine include.

includeThe tag, as one of the core functions built based on Go language and Django template engine syntax for AnQi CMS, is not just a simple code snippet reference tool, but also a "united front" for realizing the modularization, unified management, and efficient update of content across multiple sites.

Challenges of multi-site operations andincludearise

Imagine that you are running a brand website for ten different product lines, and each website needs a footer that includes the company's contact information, navigation menu, and copyright notice.If there is no unified management mechanism, you may need to repeat the same code in ten different template files.Once the company's phone number changes, or if you need to adjust the navigation structure, you will have to modify these ten files one by one, which is not only time-consuming and labor-intensive but also prone to errors.

The multi-site management function of Anqi CMS is designed to enable independent management and content publishing of multiple sites through a unified backend, greatly reducing repetitive work. However, when it comes to public elements at the template level,includeThe value of the label becomes prominent. It allows us to extract those content modules that frequently appear in multiple sites and have similar structures (such as header navigation, footer copyright information, sidebar, contact information blocks, even specific ad slots or content recommendation modules) and manage them as independent template files.

includeHow to unify the management and update of the public content module

includeThe core concept of the label is "Don't Repeat Yourself" (DRY).It allows us to dynamically embed the content of a template file into another template file.In the AnQi CMS multi-site environment, this means:

  1. Achieve global template consistency:The most direct application is the unified header and footer. You can create a namedpartial/header.htmlandpartial/footer.htmlThe public template file that contains the common structure and content of all sites. Then in each site's main template file (such asindex.html/detail.html), simply use{% include "partial/header.html" %}and{% include "partial/footer.html" %}To refer to them. This way, regardless of how many sites you have, they will share the same header and footer. When you need to update these common parts, just modifyheader.htmlorfooter.htmlThis file, all sites referencing it will take effect immediately, greatly enhancing the update efficiency and maintenance convenience.

  2. Dynamically adapt to site-specific information:The public module is not always completely static. For example, even though the header structure of all sites is the same, the displayed website name or contact phone number may vary from site to site. Anqi CMS'sincludeTags integrated with the system's built-insystemandcontactTags配合,can perfectly solve this problem. You canpartial/header.html, through{% system with name="SiteName" %}Dynamically obtain the name of the current site, or through{% contact with name="Cellphone" %}To display the contact phone number of the current site. This means, the sameheader.htmlFile, display the name and phone number of site A on site A, and display the information of site B on site B, no need to customize for each site separatelyheader.htmlThis powerful dynamic adaptability is the key to truly unified management.

    For example, a unified footer templatepartial/footer.htmlIt might look like this:

    <footer>
        <p>&copy; {% now "2006" %} {% system with name="SiteName" %}. All Rights Reserved.</p>
        <p>联系电话:{% contact with name="Cellphone" %}</p>
    </footer>
    

    This file can be accessed by all sitesincludeand automatically display their respective website names and contact information.

  3. Flexible content module combination and customization: includeLabels also support passing variables. This means that you can inject some temporary, site-specific data when importing public modules, thus achieving finer control.For example, if you have a general promotional banner modulepartial/promo_banner.htmlBut different sites need to display different promotional copy, you can use{% include "partial/promo_banner.html" with promo_text="限时优惠!免费送货" %}.promo_banner.htmlInternally, it can be accessed by{{ promo_text }}to display these passed variables. If a site does not need to display promotional information, even theincludelabel can be omitted, or it can be utilizedif_existsAvoid errors due to non-existent files.

  4. Promote modular development and teamwork:Decompose large templates into multiple manageable small modules, which not only improves the readability and maintainability of the code, but also greatly promotes team collaboration.Different developers can work on different public modules simultaneously without interfering with each other.This is an effective way to improve development efficiency and reduce communication costs for enterprises with a large number of websites or those frequently updating content.

Organization and benefits in practice

In AnQi CMS, **the practice is to store all reusable template fragments in a specialpartial/the directory, such asdesign-director.mdThe document mentions. This not only keeps the file structure clear, but also facilitates quick search and citation. CombinedextendsTags (used to define the overall page layout skeleton) andincludeTags (used to embed specific content modules), you can build a highly modular and easy-to-maintain template system.

By intelligently applyingincludeLabel, Anqi CMS helps operators achieve a qualitative leap in multi-site management: it not only greatly reduces the repetitive code writing work, ensures the high consistency of all sites in terms of visual and functional, but also raises the efficiency of website update and maintenance to an unprecedented height. Whether it is to respond quickly to market changes or unify the brand image,includeTags are an indispensable tool in the multi-site strategy of Anq CMS.


Frequently Asked Questions (FAQ)

1.includewith the tag andextendsWhat are the differences between tags in Anq CMS templates?

In simple terms,extendsThe tag is used to define the "skeleton" or "master" of a page, it regulates the overall layout structure of a page and is used toblockThe label reserves an area that can be overwritten (overwritten) by a sub-template. A sub-template usually onlyextendsA parent template.includeIt is more like embedding a small "building block" into any template (whether it is a parent template, a child template, or other 标签则更像是将一个小的“积木块”嵌入到任何模板(无论是父模板、子模板还是其他includeThe specific position of the incoming segment. It does not involve layout rewriting, but simply reuses code segments. So, you can first useextendsto build the page skeleton, and then useincludeFill in various reusable content modules.

2. Using too many in a multi-site environment,includewhether the tag will affect website performance?

The template engine of AnQi CMS is processing