As an experienced website operations expert, I am happy to give you a detailed explanation of Anqi CMSarchiveParamslabel'sidHow do parameters get used to retrieve custom fields of a specific document.Anqi CMS provides great convenience for content operation with its flexible content model and powerful template tag system.Mastering the essence of these tags can make your website content display more personalized and greatly increase operational efficiency.
To deeply explore the potential of content: usingarchiveParamsTags to get custom fields of specific documents
In the powerful feature matrix of AnQi CMS, custom fields (also known as model fields) are undoubtedly the key to enhancing the flexibility and personalized display of content.It allows you to define unique properties for different types of content (such as articles, products, cases, etc.), thus freeing yourself from the constraints of traditional CMS fixed fields.But how to accurately obtain these specific fields, especially when you need to display additional information for a specified document, it becomes particularly important.archiveParamsLabel and its core parametersidRevealing its powerful capabilities in obtaining custom fields of specific documents.
The foundation of flexibility: Anqi CMS custom fields
The reason why AnQi CMS can meet various content display needs is largely due to its 'flexible content model' design.This means that you can create an arbitrary number of custom fields for different content models (for example, an article model may contain 'author', 'source' fields; a product model may contain 'price', 'stock', 'material' fields) based on business scenarios.These fields can cover a variety of types such as single-line text, numbers, multi-line text, as well as single-choice, multiple-choice, and dropdown selections, greatly enriching the dimensions of content expression.When a document is published, editors can fill in these unique attribute values for each document.
archiveParamsLabel: Custom field aggregator
archiveParamsThe tag is a tool used in the Anqi CMS template system to obtain custom document fields.It can provide the additional fields and their corresponding values defined for the document model in a programming-friendly way to the template for rendering.
Generally, when you use on the document detail page{% archiveParams params %}When this method is called, it will automatically identify the document ID of the current page and return all the custom fields of the document. But in many cases, we may need to get the custom fields in places other than the current document detail page.SpecificThe custom field of the document. Now,idThe parameter takes the stage.
Accurate positioning:idThe magic of the parameter
archiveParamslabel'sidThe parameter allows you to explicitly specify which custom field of the document you want to retrieve.This is like pointing a label to a target, so that it no longer 'blindly' fetches the current document, but instead directly goes to the document you have preset.
For example, suppose your website has a "hot products" section that needs to display custom fields such as the "model" and "features" of a specific product.This 'hot products' area may appear on the homepage instead of the product details page.idThe parameter is used to accurately obtain the custom fields of the target product:
{# 假设我们已知要获取ID为123的产品文档的自定义字段 #}
{% archiveParams specificDocParams with id="123" %}
<p>以下是ID为123文档的自定义字段:</p>
{% for item in specificDocParams %}
<div>
<span>{{ item.Name }}:</span>
<span>{{ item.Value }}</span>
</div>
{% endfor %}
{% endarchiveParams %}
In this code block,with id="123"Make it cleararchiveParamsLabel to retrieve the custom fields of the document with ID 123. These fields will be stored inspecificDocParamsvariables, then throughforloop traversal, display the names of each custom field (item.Name) and value (item.Value)
Two access modes: ordered array and unordered mapping
archiveParamsThe tag provides two structural modes when returning custom fields, depending onsortedParameter settings:
Ordered array (
sorted=trueThe default behavior is:Whensortedparameters fortrueWhen set to (or not set, because this is the default value),archiveParamsReturns an array containing custom fields. Each element of the array is an object that includesName(the display name of the field) andValue(The field value). This pattern is very suitable for going throughforLooping through and displaying all or part of the custom fields{# 默认行为,sorted=true #} {% archiveParams docDetails with id="456" %} <h3>文档ID 456 的详细参数(有序列表):</h3> <ul> {% for field in docDetails %} <li><strong>{{ field.Name }}:</strong> {{ field.Value }}</li> {% endfor %} </ul> {% endarchiveParams %}Unordered mapping (
sorted=false):If you explicitly know the 'reference field' (which is the English field name used during backend definition, not the display name), and you want to access it directly by the field name, then you cansortedthe parameter tofalse. At this point,archiveParamsReturn a mapping (map) object where the key (key) is the name of the custom field called.{# 假设文档ID 789 有一个调用字段名为 'material' 的自定义字段 #} {% archiveParams docMap with id="789" sorted=false %} <h3>文档ID 789 的特定参数(通过字段名直接访问):</h3> <p>产品材质:{{ docMap.material.Value }}</p> {# 假设还有一个 'warranty_period' 字段 #} {% if docMap.warranty_period %} <p>保修期:{{ docMap.warranty_period.Value }}</p> {% endif %} {% endarchiveParams %}This method is very efficient when you need to quickly retrieve a small amount of specific custom fields without traversing the entire list. Please note,
docMap.material.ValueofmaterialIt is the 'invocation field' of the custom field, not the 'parameter name'.
archiveDetailThe complementarity of the tag
It is worth mentioning that if you only need to retrieve a specific document'sa singleCustom field, Anqi CMS also provides another more concise way, that is to usearchiveDetaillabel'snameparameters to specify the calling field name of the custom field.
{# 直接获取文档ID 123 的 'author' 自定义字段 #}
<p>文档作者:{% archiveDetail with name="author" id="123" %}</p>
{# 获取文档ID 123 的 'release_date' 自定义字段,并格式化时间 #}
{% archiveDetail releaseDate with name="release_date" id="123" %}
<p>发布日期:{{ stampToDate(releaseDate, "2006年01月02日") }}</p>
This way is more direct and concise when you already know which custom field you want to retrievearchiveParamsmore direct and concise.
Practical suggestions
- Flexible application
id:No matter whether it is on the home page sidebar, thematic page, or related recommendation module, whenever you need to display the unique attributes of a specific document,idthe parameters can be put to good use. - Select the acquisition mode according to your needs:If you need to display a document'sallCustom fields, or need to display in a specific order,
sorted=trueofarchiveParamscooperateforLoops are**selections. If you need to quickly access the document'sa few knowncustom fields,sorted=falseofarchiveParamsorarchiveDetailtags are more efficient. - Pay attention to the case of field names:While using
archiveParamsunordered mapping mode orarchiveDetailWhen directly accessing custom fields by label, make sure the field name (i.e., "call field") you use is exactly the same as the case used when defined in the background; otherwise, you may not be able to retrieve the data.
ByarchiveParamstags and theiridFlexible parameter application allows you to freely control the content display of Anqi CMS, bringing users a richer and more accurate website experience.
Frequently Asked Questions (FAQ)
Q: How do I know what the 'callable field' (FieldName) of a custom field is? A:In the AnQi CMS backend, go to 'Content Management' -> 'Content Model', select the model you have defined with custom fields.Edit the model, and you will see the settings of each custom field, where there will be an option for 'Field Name' or 'Field Call' (usually alphabetic).This name is the key you need to use when directly accessing the field in the template.
materialThen it can be used in the template.docMap.material.Valueor{% archiveDetail with name="material" %}Get it.Q:
archiveParamsandarchiveDetailWhat are the differences and **use cases when getting custom fields? A:archiveParams:Mainly used for gettingAll (or multiple) custom fields of a document.- When
sorted=trueIt returns a container that includesNameandValueAn ordered array, suitable for iterating to display all custom fields, especially when you need to display the field's 'display name'. - When
sorted=falseWhen, return an unordered mapping with the 'calling field' as the key, suitable for directly accessing known field names.
- When
archiveDetail:Mainly used for gettingA single field of a document(including regular fields such asTitle/Content,