As an experienced website operation expert, I am well aware that accurately calling and displaying the details of the content model in a flexible and efficient content management system like AnQiCMS is the key to building a functional and user-friendly website.The Anqi CMS, with its powerful custom content model capabilities, allows us to flexibly build data structures based on various business needs (whether articles, products, or event pages).Today, let's delve deeply into the process of template development using AnQiCMS,moduleDetailHow tags support us in specifying and obtaining details of the desired content model.

In-depth Analysis of AnQiCMSmoduleDetailTags: How to accurately obtain the content model you want.

In the AnQiCMS template system,moduleDetailTags play a role in obtaining detailed information about specific content models.It is not just a simple data pull, but also the foundation for us to achieve highly customized content display.Imagine that your website has three different types of content models, 'articles', 'products', and 'services', each with its unique fields and display logic.When you need to display metadata of a content model (such as the model name, description, or link) on a page, such as a sidebar or a specific module,moduleDetailTags come in handy.

Tell the system exactly which content model you want to obtain,moduleDetailTags mainly provide two key parameters:idandtokenIn addition, if you are operating in a multi-site environment, there is also asiteIdParameters can be used.

1. By model ID (id) to specify the model

The most direct and accurate way is to use the unique identifier of the content model —idSpecify. Each content model created in the AnQiCMS backend will have a system-generated numeric ID.If you know the ID of the content model you want to call, you can pass it directly as a parameter tomoduleDetail.

For example, if you want to get the model details of the model with ID 1 (usually the default article model), you can use it like this:

<div>文章模型名称:{% moduleDetail with name="Title" id="1" %}</div>

Here, id="1"Tell exactlymoduleDetailLabel to find the content model with ID 1, then go throughname="Title"Get the name of the model and display it. This method is suitable when you have a clear understanding of the model ID, or need to hardcode a specific model in the template.

2. By model URL alias (token) to specify the model

In addition to the numeric ID, AnQiCMS also allows you to set a SEO-friendly URL alias for the content model, namelytoken. This alias is usually the lowercase letter combination of the model, such as "article" or "product"。When you need to specify a model in a template in a more readable or URL-structured way,tokenParameters make it very convenient.

Assuming your product model URL alias is 'product', you can get the link like this:

<div>产品模型链接:{% moduleDetail with name="Link" token="product" %}</div>

UsetokenThe benefit is that even if the internal ID of the model changes, as long as the URL alias remains the same, your template code will still work properly, which brings convenience to the maintenance of the template.

3. Cross-site call model information (siteId)

One of the highlights of AnQiCMS is that it supports multi-site management, which means you can operate multiple independent websites within a single system.In some advanced application scenarios, you may need to call information about a content model created by another site in the current site template. At this point,siteIdThe parameters took effect.

If you have a sub-site with ID 2 and you want to get the model name with ID 3 in that site, you can do it like this:

<div>子站点模型名称:{% moduleDetail with name="Title" id="3" siteId="2" %}</div>

It should be noted that,siteIdGenerally, it is only necessary to specify explicitly in a multi-site environment. By default,moduleDetailThe tag automatically retrieves the content model information of the current site, so if you only manage one site or only call the model of the current site, you can omit this parameter.

4. Get the specific attributes of the model (name)

Once you specify which content model to retrieve, the next step is to determine which part of the model's information you want to display. This is done bynameParameter to achieve.moduleDetailThe tag supports retrieving various built-in properties of content models, including but not limited to:

  • Id: The numeric ID of the model.
  • Title: The display name of the model in the background (such as “Article”, “Product”).
  • Name: The English name of the model (usually similar to the token, but may be used for internal identification in some contexts).
  • Keywords: Keywords at the model level.
  • Description: Brief introduction at the model level.
  • Link: The home page link of the model.
  • TableName: The table name corresponding to the model in the database (often used for developers' reference).

You can optionally display these properties as needed. If not specifiednameThe parameter, or assignmoduleDetailAs an assignment of a variable, you can obtain the entire model object and then access its properties through dot notation.

For example, assign the entire model object to a variable and display its introduction:

{% moduleDetail articleModel with id="1" %}
<div>文章模型简介:{{ articleModel.Description }}</div>

In summary,moduleDetailThe tag is a powerful tool in AnQiCMS template development, which empowers developers to accurately obtain and display content model metadata. By flexibly usingid/tokenandsiteIdParameters, you can easily master the call logic of the content model, combiningnameThe parameter retrieves the required attributes to build highly dynamic and customizable website pages.Mastering the use of these parameters will greatly enhance your efficiency and flexibility in AnQiCMS content operation and template creation.


Frequently Asked Questions (FAQ)

  1. moduleDetailTags andarchiveDetailWhat are the differences between tags?

    • moduleDetailUsed to getThe content model itselfdetails, such as the name, description, or link of the 'Article Model'. It focuses on the metadata of content structure types.
    • archiveDetailis used to geta specific documentdetails, such as the title, content, and publication time of a specific “article”. It focuses on the specific content entities under the model. In simple terms,moduleDetailThe information obtained is of the type 'article' andarchiveDetailThe content of this specific article about the latest news of AnQiCMS.
  2. moduleDetailCan the tag get the list of all content models?

    • No.moduleDetailThe tag was designed initially to geta singleThe details of the content model. If you need to retrieve a list of all content models or iterate through them, you usually need to go through other specialized tags (such as possibly existingmoduleListAlthough the document does not directly display this label, AnQiCMS design usually provides a similar function) or process it in the controller layer.moduleDetailThe essence lies in "details" rather than "list".
  3. If I don't know the model'sidortokenhow should I look for it?

    • You can log in to the AnQiCMS backend management interface, under the "Content Management" section, to view and manage all created content models.Each model will clearly display its ID and URL alias (token).This is the most direct and reliable way to search.