AnQi CMS is a powerful enterprise-level content management system, and its multi-site management capability undoubtedly provides great convenience and flexibility for operators.How to ensure that each site can accurately call its exclusive information when managing multiple brands or sub-sites, especially for critical data such as contact information, is particularly important.siteIdThe recognition and data call of parameters in the contact information label is correct.
KnowsiteIdThe role in the multi-site environment.
The Anqi CMS allows multiple sites to share a single core system, with each site having its own configuration, content, and management backend. To distinguish the data of these sites, the system assigns a unique identifier to each site, namely,siteIdWhen you need to get data from a *non-current access site* in the template,siteIdit becomes the key to indicating the data source.
For example, a company may have a main site and sub-brand sites, which are managed under the same AnQiCMS system. The contact phone number of the main site is123456789The contact phone number of the sub-brand site is987654321In the main station's template, if I want to display the contact phone number of the sub-brand station instead of just the main station's own phone number, this is when it is necessary to specify it clearly.siteIdto do so.
contactTags are powerful tools in AnQi CMS used to obtain various information items from the "Contact Information Settings" in the background, such as contacts, phone numbers, addresses, email addresses, WeChat, etc. By default, if not specifiedsiteIdIt will automatically call the contact information of the site being visited. However, in the scenario of cross-site data calls,siteIdthe precise use is indispensable.
Prepare test environment: Build distinguishable multi-sites
To effectively testsiteId, first we need a clear multi-site environment.
- Set up at least two sites:Ensure that your security CMS system is configured with at least two independent sites.You can refer to the documentation of AnQi CMS, such as the tutorial 'How to install AnQi CMS using Baota Docker' or 'Tutorial on adding multiple AnQi CMS sites via reverse proxy', to complete this step.
- Configure unique contact methods:This is a test
siteIdWhether the key recognition is correct.- Log in to the backend of the first site (we call it "Site A") and go to "Backend Settings" -> "Contact Information Settings".Set the contact phone number to a clear and recognizable value, such as 'Site A exclusive phone: 111-1111-1111'.
- Similarly, log in to the backend of the second site (“Site B”) and go to “Backend Settings” -> “Contact Information Settings”.Set the contact phone number to a completely different, clearly identifiable value, such as "Site B专用电话:222-2222-2222".
- To get the site.
siteId:In the AnQi CMS backend, you can usually find the unique for each site in the "Multi-site Management" list, or when viewing the configuration details of each sitesiteId. Suppose site A'ssiteIdYes1,Station B's site,siteIdYes2. Please remember these IDs, they will be used for template calls.
Implementation of test: Calling contact information of different sites in the template
Now, we will write code in the template to verifysiteIdFor convenience of testing and comparison, we can choose a public template file, such asbash.html(usually contains header or footer information, which will be loaded on all pages), or create a dedicated test page template.
Assuming we choose to place it on a certain page,<body>add test code inside:
{# 假设我们正在访问站点A(siteId=1) #}
<h3>联系方式数据调用测试 - 当前站点A</h3>
{# 1. 不指定siteId:默认应显示当前站点(站点A)的联系电话 #}
<p>
<strong>当前站点默认电话:</strong>
{% contact with name="Cellphone" %}
</p>
{# 2. 明确指定siteId为站点A的联系电话 #}
<p>
<strong>明确指定站点A电话(siteId=1):</strong>
{% contact siteA_phone with name="Cellphone" siteId="1" %}{{ siteA_phone }}
</p>
{# 3. 明确指定siteId为站点B的联系电话 #}
<p>
<strong>明确指定站点B电话(siteId=2):</strong>
{% contact siteB_phone with name="Cellphone" siteId="2" %}{{ siteB_phone }}
</p>
<hr>
{# 假设我们现在模拟访问站点B(siteId=2) #}
<h3>联系方式数据调用测试 - 当前站点B (仅供理解,实际需访问站点B URL)</h3>
{# 以下代码在实际访问站点B时才会生效 #}
{# 1. 不指定siteId:默认应显示当前站点(站点B)的联系电话 #}
<p>
<strong>当前站点默认电话(访问站点B时):</strong>
{% contact with name="Cellphone" %}
</p>
{# 2. 明确指定siteId为站点A的联系电话 #}
<p>
<strong>明确指定站点A电话(siteId=1,访问站点B时):</strong>
{% contact siteA_phone_on_B with name="Cellphone" siteId="1" %}{{ siteA_phone_on_B }}
</p>
{# 3. 明确指定siteId为站点B的联系电话 #}
<p>
<strong>明确指定站点B电话(siteId=2,访问站点B时):</strong>
{% contact siteB_phone_on_B with name="Cellphone" siteId="2" %}{{ siteB_phone_on_B }}
</p>
Please note that the test code in the second paragraph "Current site B" above is to help you understand the expected result. In fact, you only need to deploy the first paragraph of code to your public template and then visit the frontend pages of site A and site B to verify.
Validation result: Check if the data call is correct
Access the frontend page of site A:
- Observe the value displayed at
- Observe the value displayed at "明确指定站点A电话(siteId=1)
- Observe the value displayed at
Access the front-end page of site B:
- Observe the value displayed at
- Observe the value displayed at "明确指定站点A电话(siteId=1)