In the practice of template development in Anqi CMS,{% diy %}The use of tags is very frequent, it provides great flexibility for website operators, allowing them to customize and call various information from the background configuration.However, many developers may be confused about whether it can accurately call a custom configuration for a specific content model such as 'Only for article modules'.Today, as an experienced website operations expert, I will deeply analyze this mechanism based on the Anqi CMS documentation and guide you on how to correctly use template tags in different scenarios.
The configuration system of AnQi CMS: Understanding the boundaries of global and local
To understand{% diy %}The range of capabilities of the label, we first need to have a clear understanding of the configuration system of AnQi CMS. AnQi CMS, in its design, has logically divided the configuration information of the website, which can mainly be summarized into two categories:
Global Custom Configuration:These configurations are usually general settings within the scope of a website, not attached to a specific content type.For example, you can customize the "record number", "website name", and other such items in the "Global Function Settings" backend, or add a "WhatsApp contact" in the "Contact Information Settings".This information is uniform and callable regardless of whether you visit the article detail page, product list page, or single page.
{% diy %}The label is born for this kind of global custom configuration.It allows you to conveniently call these globally added flexible parameters in the template.{% diy with name="Author" %}Get its value.Content Model Custom Field:Different from the global configuration, the custom field of the content model is a customized extension for specific content types (such as articles, products).One of the core highlights of AnQi CMS is its 'flexible content model' feature, which allows users to customize content models according to business needs and add unique fields for each model.For example, for the "article model", you may want to have fields such as "article author", "source", and "recommendation index", etc.; while for the "product model", you may need fields such as "product price", "inventory", and "model", etc.These fields are the attributes of the content items themselves, they only exist in the specific documents of the content model, not the global settings of the website.The document clearly states: "You can set fields that only this model has in the content model.
{% diy %}Why does the label not directly call the module custom configuration?
Now we return to the core issue:{% diy %}Can the tag be used to call a custom configuration for a specific module, such as only for the article module?
The answer is:Custom field configuration cannot be used directly to call a specific module (such as the article module).
This is not{% diy %}A missing label function, but an embodiment of its design positioning.{% diy %}The tag is responsible for retrieving the globally defined key-value pair data from the background "Custom Content" area.It lacks context awareness, cannot automatically identify the content model associated with the current page (such as an article model), and thus cannot read a specific custom field under the model.
Imagine{% diy %}As a question asking 'What is the current name of the website?'}]A general-purpose robot, it can accurately answer 'Anqi CMS', but if you ask it 'Who is the author of this article?'}]It will say, "I don't know, this is not within my scope of responsibility."}]Because the author information of the article belongs to the article itself, not the global settings of the website.
How to correctly call the custom configuration of the article module?
If we need to display unique custom fields in the article detail page, such as 'source of the article' or 'author', which tag should we use?
The AQ CMS provides dedicated tags with enhanced contextual awareness:{% archiveDetail %}and{% archiveParams %}.
Use
{% archiveDetail %}Invoke a single custom field:When you know that a certain article (or product) model has a specific custom field and you want to directly obtain its value,{% archiveDetail %}Tags are an ideal choice. The document mentions that,“Other field parameters of the document model settings”can be accessed by{% archiveDetail with name="字段名称" %}the way. For example, if you define a namedauthorCustom field, you can call it like this in the article detail template:<p>文章作者:{% archiveDetail with name="author" %}</p>Or, if you want to assign the value to a variable before using it:
{% archiveDetail articleAuthor with name="author" %} <p>文章作者:{{ articleAuthor }}</p>This, on the detail page of each article, will display the author information filled in for the article.
Use
{% archiveParams %}Traverse all custom fields:Sometimes, you might want to iterate through all the custom fields of an article (or product) or render them differently based on the field type. At this time,{% archiveParams %}The label came in handy.It will return an array object containing all custom parameters, which you can iterate over.<h3>文章参数详情:</h3> {% archiveParams params %} <ul> {% for item in params %} <li>{{ item.Name }}:{{ item.Value }}</li> {% endfor %} </ul> {% endarchiveParams %}This code will dynamically list all the custom field names and values of the article without you knowing all the field names in advance.
Practical scenario examples
To understand it more intuitively, let's look at a few simple examples:
Scenario one: Call the global contact information of the website (e.g., QQ number)Assuming you have added a parameter named "QQ" with the value "123456789" in the "Contact Information Settings" under the "Custom Settings Parameters" in the background. You can call it like this on any page of the website (including the article detail page):
<p>我们的客服QQ:{% diy with name="QQ" %}</p>
Here to use{% diy %}The label is correct because it retrieves the global custom contact information.
Scenario two: calling the 'source' field unique to the article model.Suppose you have added a custom field named "source" (source) to the "Content Model" in the "Article Model". In the template of the article detail page, you need to call it like this:
<p>文章来源:{% archiveDetail with name="source" %}</p>
This cannot be used{% diy %}Because it cannot perceivesourceIt is a specific field of the current article.
Summary
AnQi CMS fully considers the different levels and usage scenarios of configuration information when designing its template tags.{% diy %}Tags are what you getGlobal custom configurationThe tool for those who need to delve into the website-level settings that are unrelated to specific content types.Custom fields unique to content models such as articles and productsthen,{% archiveDetail %}and{% archiveParams %}Tags are your choice.
Understanding the scope of these tags will help you use the powerful features of Anqicms more efficiently and accurately, building a website that is clear in structure and easy to maintain.
Frequently Asked Questions (FAQ)
Q:
{% diy %}Tags and{% system %}What are the differences between tags?A:{% system %}The label is mainly used to call the built-in, system-level global configurations of Anqi CMS, such asSiteName(Website name),SiteLogo(Website Logo) and others. And{% diy %}Labels are used to call the custom global key-value pairs information that you add in the background "Global Feature Settings" or "Contact Information Settings" modules, etc. In other words,{% system %}Is calling a fixed item,{% diy %}Is calling your extended global item.Q: Can I use it in a loop,
{% archiveDetail %}To directly call the custom fields of all articles?A:{% archiveDetail %}Tags are mainly used to obtain specific fields of a single content item, if you want to{% archiveList %}There are two common methods to obtain custom fields of each article in a loop:- Call the known custom field one by one within the loop, for example
{% for item in archives %}<p>{{ item.Title }} - 作者: {% archiveDetail with name="author" id=item.Id %}</p>{% endfor %}. - It is more recommended to, in
{% archiveList %}repeatedlyitemThe variable, the custom field is usually directly present as its attribute, you can use it directly{{ item.自定义字段名 }}Call, for example{{ item.author }}If there are many fields and need to be processed uniformly, you can also process it in the loop{% archiveParams params with id=item.Id %}To get the currentitemAll custom parameter lists and iterate over them.
- Call the known custom field one by one within the loop, for example
Q:
{% diy %}Can the tag call the global configuration of other sites?A: Yes,{% diy %}Tag supportsiteIdParameter. If you have enabled the multi-site management feature in the AnQi CMS backend and want to call the global custom configuration of other sites in the template of the current site, you can specifysiteIdParameter