AnQi CMS is an enterprise-level content management system designed specifically for small and medium-sized enterprises, self-media, and multi-site management, and its multi-site management capability is undoubtedly one of its core highlights.In daily operations, we often encounter such a scenario: we hope to display certain information of the child site on the main site, or to carry out cross-references of content or data models between different sites.Today, let's delve into a specific and practical scenario - how to usemoduleDetailTag to get the content model data of other sites.
The underlying logic of Anqi CMS multi-site deployment
Before delving into the technical details, let's briefly understand the intricacies of the Anqi CMS multi-site deployment.AnQi CMS is not just running multiple systems independently, but rather, it distinguishes different sites through independent databases and configuration files based on a core code basis.This means that although each site has its independent backend management interface, content data, and front-end display, they share the same program core.This design makes cross-site data referencing possible, greatly enhancing management efficiency and content reuse.Each child site created in the background "Multi-site Management" will be assigned a uniquesiteIdThis is the key identifier for cross-site data operations.
moduleDetailLabel: A tool for obtaining content models
moduleDetailThe tag plays a role in the Anqi CMS template system in obtaining detailed information about a specific content model.It can help us retrieve the ID, name, link, table name, and even custom fields of a certain content model.In a single-site environment,moduleDetailIt will default to fetching the content model information under the current site. But when it comes to multiple sites, its strength is highlighted by an additional parameter - that issiteId.
By usingmoduleDetailSpecify the tagsiteIdParameter, you can explicitly tell the system which site's content model you want to query. Combinedid(Content Model ID) ortoken(Content model URL alias) parameter, you can accurately locate the specific content model on the target site and extract its related data.
moduleDetailThe tag supports getting the following core fields, which are very useful for displaying an overview of the content model:
- Id: The unique identifier of the content model.
- Title: The Chinese title or display name of the content model.
- Name: The English name or URL alias of the content model, often used in pseudo-static paths.
- Keywords: The keywords set for the content model.
- Description: A brief description of the content model.
- Link: The homepage link of the content model.
- TableName: The corresponding data table name of the content model in the database.
Practice exercise: Retrieve product model information of the child site
Suppose you have a main site (Site A,siteIdas 1) and a child site specifically for displaying products (Site B,siteIdIn order to 2). Now, you want to display the name and link of the "product" content model from Site B on a page in the main site (Site A).
Step 1: Determine the target site.siteIdand content model information
You need to log in to the AnqiCMS backend management interface, go to "Multi-site Management" to view the child site B'ssiteId. Assuming that Site B'ssiteIdIs2.
Next, go to the backend of Site B, enter "Content Management" -> "Content Model", find the "Product" content model. Click edit to view its "Model ID" (for example:3Or "URL alias" (e.g.,)product). Here we use ID to demonstrate.
Step two: Build in the main site template.moduleDetailTag
Now, we return to the template file of the main site (Site A). You can use it at any location where you want to display this information.moduleDetail.
{# 在主站点(Site A)的模板中,获取子站点(Site B,siteId=2)的“产品”内容模型(ID=3)的标题 #}
{% moduleDetail productModelTitle with name="Title" id="3" siteId="2" %}
<p>子站点产品模型的标题是:{{ productModelTitle }}</p>
{# 获取子站点(Site B)的“产品”内容模型(ID=3)的链接 #}
{% moduleDetail productModelLink with name="Link" id="3" siteId="2" %}
<p>子站点产品模型的链接是:<a href="{{ productModelLink }}">{{ productModelLink }}</a></p>
{# 更全面的方法:获取整个内容模型对象,然后从对象中提取多个字段 #}
{% moduleDetail fullProductModel with id="3" siteId="2" %}
<div class="other-site-product-model-info">
<h3>来自其他站点的产品模型信息</h3>
<p>模型ID:{{ fullProductModel.Id }}</p>
<p>模型名称:{{ fullProductModel.Title }}</p>
<p>模型URL别名:{{ fullProductModel.Name }}</p>
<p>模型表名:{{ fullProductModel.TableName }}</p>
<p>模型首页:<a href="{{ fullProductModel.Link }}" target="_blank">{{ fullProductModel.Link }}</a></p>
<p>模型描述:{{ fullProductModel.Description }}</p>
</div>
In this way, the main site (Site A) can successfully obtain and display the detailed information of the product content model in the sub-site (Site B).This cross-site call feature provides great flexibility for your multi-site operation, allowing you to easily share and display key data across different sites according to your business needs.
Further Thinking:siteIdUniversality of Parameters
It is worth mentioning,siteIdThe parameter is notmoduleDetailTags are unique. In the Anqi CMS template tag system, many tags related to content, categories, tags, and other data, such asarchiveList(Document list),categoryList(Category list),tagList(Tag list) and others, are supportedsiteIdThis means that as long as you know the target site's parameters.siteIdYou can flexibly call and display various content data from other sites, realizing the true cross-site content integration and operation.This design concept greatly simplifies the complexity of data intercommunication among multiple sites, making the implementation of content operation strategies more efficient and convenient.
Frequently Asked Questions (FAQ)
Ask: How do I know about my other sites?
siteIdare?Answer: You can log in to the backend management interface of your Anqi CMS main site and navigate to the "Multi-site Management" menu. There, you will see a list of all created child sites, each clearly marked with the correspondingsiteIdThis ID is a unique identifier automatically assigned by the system.Question: Can I use parameters to get content from other sites?
siteIdCan I use parameters to get content from other sites?Answer: Of course you can!siteIdThe parameter is a general mechanism implemented by Anqi CMS for cross-site data access. In addition,moduleDetailtags, you can also use inarchiveList(Retrieve document list) ,archiveDetail(Get document details),categoryList(Get category list),categoryDetail(Retrieve category details) ,tagList(Using multiple core content tags such as)siteIdParameters to call and display the corresponding content of other sites on the current site.Question: If the target site's
idortoken(URL alias) Will my call fail if it changes in the future? Is there a more stable way to specify the content model?Answer: Use the content model.idIt is accurate, but if the ID may indeed change, usetoken(URL alias) would be a safer choice, as URL aliases are usually more stable and more readable. For example, you can usetoken="product"Insteadid="3"Specify the product model. In practice, it is recommended to choose based on the management specifications and stability of your site's content model.idortoken.