How to call the homepage Banner data of different sites under multi-site management?

Auto CMS is an efficient and flexible content management system. Its multi-site management feature is undoubtedly a powerful assistant for many enterprises and operators to improve efficiency and expand their business scope.How to cleverly call content between different sites in a multi-site architecture, especially for key visual elements like the homepage banner, is a common problem encountered in website operation.bannerListLabels, accurately call the home page Banner data from different sites.

Flexible control of multiple sites: AnQiCMS's unique advantages

AnQiCMS multi-site management feature allows you to easily build and independently operate multiple websites. Whether it is a group enterprise with different brand lines or an operation team focusing on specific regions or service segments, everyone can benefit from it. Each site within AnQiCMS has independent configurations, content models, and data storage. At the same time, the system also provides powerful cross-site data calling capabilities, which is the core topic we are discussing today - throughsiteIdthe parameter.

In AnQiCMS, each new site created through the background 'Multi-site Management' feature will be assigned a unique numeric ID by the system. This ID is the key for cross-site data calls in the template.It ensures that you can explicitly specify the data from B site in your template on Site A, rather than the default data from the current site.

bannerList标签:首页Banner调用的工具

bannerListThe tag is a special tag in the AnQiCMS template system used to retrieve the home page banner data.Its basic usage is very intuitive, usually used to cyclically output preset carousels on the homepage of a website or on pages that need to display banners.

{% bannerList banners %}
    {% for item in banners %}
    <a href="{{item.Link}}" target="_blank">
        <img src="{{item.Logo}}" alt="{{item.Alt}}" />
        <h5>{{item.Title}}</h5>
    </a>
    {% endfor %}
{% endbannerList %}

In the above code,banners是您为Banner数据定义的变量名,您可以在循环中访问每个Banner的Id/Logo(image address),Link[Link address],Description(Introduction) andAlt(Image alt text) and other properties.

bannerListtags support antypeParameter used to call the background creation of different Banner groups. For example, if you have set up a "Home Banner" group in addition to the "Activity Banner" group in the background,type="活动Banner"to call it.

{% bannerList activityBanners with type="活动Banner" %}
    {# 循环输出活动Banner数据 #}
{% endbannerList %}

Crossing the barriers of stations:siteIdThe magic of

Now, let's focus on how to usebannerListTag calls to fetch Banner data from different stations. The answer lies in its support forsiteIdParameter.

siteIdThe parameter allows you to explicitly specify which site to get Banner data from. When you do not providesiteIdwhenbannerListThe label will fetch the Banner from the current site by default. Once you specifysiteIdTags will search for the corresponding ID of the site data.

For example, suppose you have a main site (Site A,)siteIdand two child sites (Site B,)}siteIdEnglishsiteIdYou want to display not only the main site's Banner on the homepage template of the main site, but also the Banners of sub-sites B and C.

The following is an example of code that achieves this goal in the main site template:

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>主站点首页 - 多站点Banner调用演示</title>
    {# 引入CSS和JS #}
</head>
<body>
    <header>
        <h1>主站点</h1>
    </header>

    <main>
        <h2>主站点自己的首页Banner</h2>
        <div class="banner-section main-site-banners">
            {% bannerList mainSiteBanners %}
                {% for item in mainSiteBanners %}
                <div class="banner-item">
                    <a href="{{item.Link}}" target="_blank">
                        <img src="{{item.Logo}}" alt="{{item.Alt}}" />
                        <p>{{item.Description}}</p>
                    </a>
                </div>
                {% empty %}
                <p>主站点暂无Banner数据。</p>
                {% endfor %}
            {% endbannerList %}
        </div>

        <h2>子站点B (siteId: 2) 的首页Banner</h2>
        <div class="banner-section sub-site-b-banners">
            {% bannerList siteBBanners with siteId="2" %} {# 指定siteId为2,调用子站点B的Banner #}
                {% for item in siteBBanners %}
                <div class="banner-item">
                    <a href="{{item.Link}}" target="_blank">
                        <img src="{{item.Logo}}" alt="{{item.Alt}}" />
                        <p>{{item.Description}}</p>
                    </a>
                </div>
                {% empty %}
                <p>子站点B暂无Banner数据。</p>
                {% endfor %}
            {% endbannerList %}
        </div>

        <h2>子站点C (siteId: 3) 的“促销活动”Banner分组</h2>
        <div class="banner-section sub-site-c-promos">
            {% bannerList siteCPromotionBanners with siteId="3" type="促销活动" %} {# 指定siteId为3,并指定type为“促销活动” #}
                {% for item in siteCPromotionBanners %}
                <div class="banner-item">
                    <a href="{{item.Link}}" target="_blank">
                        <img src="{{item.Logo}}" alt="{{item.Alt}}" />
                        <p>{{item.Description}}</p>
                    </a>
                </div>
                {% empty %}
                <p>子站点C的“促销活动”Banner分组暂无数据。</p>
                {% endfor %}
            {% endbannerList %}
        </div>
    </main>

    <footer>
        <p>&copy; 2023 AnQiCMS 多站点演示</p>
    </footer>
</body>
</html>

In the above example, we clearly demonstrate how to achieve this bybannerListtag.siteId="X"Parameters, to accurately obtain Banner data from the site with ID X. At the same time, we can also combinetypeThis parameter allows calling a specific group's Banner, which provides great flexibility.

Attention Points and **Practice

  1. ConfirmsiteIdBefore making cross-site calls, be sure to find the target site you want to call data from in the 'Multi-site Management' interface of AnQiCMS backend.siteId. Usually this ID will be displayed directly in the site list or viewed by clicking on the site edit to check the URL parameters.
  2. Existence of data:bannerListThe label will only call the target site withinAlready existsThe Banner data. If the target site has not set a Banner, or does not have the one you specifiedtypeGroup Banner, the tag will return an empty array. Therefore, add it to the template.{% empty %}Handling branches to process no data is a good habit, which can avoid blank pages or display errors.
  3. Performance considerations:Although AnQiCMS is developed based on Go language with excellent performance, cross-site data calls will inevitably involve additional database queries.When designing, it should weigh the call frequency and data volume to avoid unnecessary performance overhead.For static content or infrequently updated Banners, caching mechanisms can be considered.
  4. Template universalityIf you need a template that can be reused across multiple sites and each site displays its own Banner,bannerListthere is no need to specify in the tag.siteId,Let it default to retrieve the current site's Banner. Only use it when you really need to display the Banner of other sitessiteId.
  5. Permissions and Security:AnQiCMS has already handled the data access permission control at the bottom level. At the template level, as long as you can access this tag, you can obtain the data without the need for additional permission configuration.

Summary

AnQiCMSbannerListTag combinationsiteIdParameters, providing a concise and powerful solution for content calls under multi-site management.Whether it is the main station gathering the essence of the sub-stations, or the sub-stations referencing the content of the main station, this flexible calling method can meet your operational needs.Mastering this skill will enable you to navigate the multi-site operation of AnQiCMS with ease, and manage and display website content more efficiently.

Common Questions and Answers (FAQ)

Q1: How do I know each site?siteIdWhat is it? A1:You can view it in the "Multi-site Management" interface of the AnQiCMS backend.The basic information of the site, including its unique numeric ID, is usually displayed on each line of the site list.id=Xsuch parameters, where X is the site of the