How to obtain the basic configuration information of a specified site when operating multi-site?

AnQiCMS (AnQiCMS) provides great convenience to operators with its excellent multi-site management capabilities.Whether you have multiple brand sites under your company, regional sub-sites, or need to build independent content portals for different business lines, AnQiCMS can efficiently manage them in a unified backend.However, in actual operation, you may encounter such a scenario: in a site template, it is necessary to obtain the basic configuration information of another site, such as its website name, logo, URL, or contact information.This is when the powerful system tags of Anqi CMS come into play.

Unlock multi-site configuration information: The Art of AnQiCMS System Tags

The template engine of AnQiCMS is designed to be very flexible, it can not only obtain various data from the current page, but also through the introductionsiteIdParameters, break the data barriers between sites, allowing you to easily 'peek' into the basic configuration information of other sites in any site template.This is like having a dedicated information officer for each of your sites, always ready to follow your command.

1. Core weapon:systemwith the tag andsiteIdParameter

To obtain the basic configuration information of the specified site, we first need to summon the most core system setting tag of AnQiCMS -system. This tag is used to retrieve the global configuration of a website, such as the website name, logo, filing number, etc. Usually, when you use it in a template,{% system with name="SiteName" %}When such a label is used, it will automatically retrieve the name of the current site.

But when you need to getAnother sitethe name of the site, just usesystemadd in thesiteIdparameter. ThissiteIdIt is the unique ID corresponding to each site in the "Multi-site Management" feature of the Anqi CMS backend. You can view the unique ID of each site in the multi-site list on the backend.siteId.

For example, assume you have onesiteIdWith2sub-site, whose website name is 'AnQi Mall', and you want to display it at some location on the main site:

{# 获取siteId为2的站点的网站名称 #}
{% system subSiteName with name="SiteName" siteId="2" %}
<div>欢迎访问我们的兄弟站点:{{ subSiteName }}</div>

By this means,subSiteNamea variable will be storedsiteIdWith2The name of the site. You can replace it according to your actual needs.siteIdTo get the configuration of different sites, you can use the value.

In addition to the site name,systemTags also support getting other rich configuration information, such as:

  • Website Logo (SiteLogo):
    
    {% system subSiteLogo with name="SiteLogo" siteId="2" %}
    <img src="{{ subSiteLogo }}" alt="安企商城Logo" />
    
  • The home page address (BaseUrl):
    
    {% system subSiteUrl with name="BaseUrl" siteId="2" %}
    <a href="{{ subSiteUrl }}">前往安企商城</a>
    
  • Website filing number (SiteIcp), Copyright information (SiteCopyright), Custom parametersThey can all be changed in the same way, just need to modifynameto get the value of the parameter.

2. Extended Applications:contact/tdkas well asdiyTag

siteIdThe power of the parameter is far more than just that.systemLabel. Many other basic information labels in AnQi CMS also support itsiteId, allowing you to obtain the detailed configuration of the specified site more comprehensively.

  • Get the contact information of the specified site (contactLabel):Assuming you want to obtainsiteIdWith3the contact phone number of the site:

    {% contact subSitePhone with name="Cellphone" siteId="3" %}
    <div>如需帮助,请拨打:{{ subSitePhone }}</div>
    

    You can also obtain its contact address, email, WeChat, etc., just by replacing thenameparameter withAddress/Email/WechatLeave the corresponding fields unchanged.

  • Get the SEO configuration of the specified site (tdkLabel):It is very useful to obtain the title, keywords, and description of a specified site when performing cross-site SEO strategies or data presentation:

    {% tdk subSiteTitle with name="Title" siteId="2" %}
    <meta name="other-site-title" content="{{ subSiteTitle }}">
    

    Similarly, replacenameparameters forKeywordsorDescriptionJust do it.

  • Get custom configuration (diyLabel):If you have customized some parameters in the background "Global Function Settings" of a site, such as a specific "Announcement Link", you can also access it bydiyTags andsiteIdto get:

    {% diy subSiteNoticeLink with name="NoticeLink" siteId="2" %}
    {% if subSiteNoticeLink %}
    <div><a href="{{ subSiteNoticeLink }}">查看安企商城的最新公告</a></div>
    {% endif %}
    

The flexible application of these tags makes it easy to call data during multi-site operations, greatly enhancing the efficiency of template development and the ability to integrate data.

Practical suggestions and precautions

  1. clearsiteId:While usingsiteIdBefore the parameter, please make sure to confirm the site information you need to obtain in the "Multi-site Management" of the AnQiCMS backend.siteIdThis is the premise of accurate data calling.
  2. Reasonable planning:Even though cross-site data calls are convenient, it is recommended that you plan according to your actual needs.Avoid calling a large amount of complex data from other sites too frequently on a single page, as this may have a subtle impact on page loading performance (though AnQiCMS is based on Go language and performs excellently, good habits are still crucial).
  3. Test verification:In the process of template development, you can first print out the variables obtained, such as{{ subSiteName | dump }}, to verify that the data is correctly obtained, which helps to quickly troubleshoot issues.

AnQiCMS system tag matchingsiteIdParameters, it has given wings to your multi-site content operation. From now on, no matter where the data is located on any site, you can easily handle it and achieve richer and smarter content display strategies.


Frequently Asked Questions (FAQ)

Q1: How do I find a specific site?siteId?A1: You can log in to the AnQiCMS backend and go to the \siteId. You can also set the ID automatically when creating a new site.

Q2: Can I set up through basic configuration information?siteIdGet the list of articles, classification information, and other contents from other sites?A2: Absolutely. Many content tags like AnQiCMS'sarchiveList(Document list),categoryList(Category list),pageListEven (single-page list) eventagList(Tag list) and also supportsiteIdParameters. This means you can be very flexible in displaying specific content from other sites on any site, for example, by aggregating and displaying the latest articles from all child sites on a portal site.

Q3: If I provided the wrongsiteId, or thatsiteIdthe corresponding site does not exist, will the template report an error?A3: Normally, the AnQiCMS template engine handles this situation in a friendly manner. IfsiteIdThe site does not exist or the site does not have the specific field value you are trying to retrieve. Tags usually return null or default values, which will not directly cause a template rendering error. This makes the template more robust in the face of missing data, but for accuracy, it is still recommended that you ensuresiteIdthe correctness.