How to retrieve and display the custom parameter field value of the article through template tags in AnQiCMS?

Calendar 👁️ 69

In AnQiCMS (AnQiCMS), the custom parameter field provides great flexibility and scalability for website content.As a website operator familiar with Anqi CMS, I know how to effectively use these fields and display them on the website front end to meet diverse content display needs.This article will detail how to obtain and display the custom parameter field value of the article through AnQi CMS template tags.

Understanding the custom parameter field of AnQiCMS

AnQi CMS allows users to customize content models according to business needs.This means that in addition to standard fields such as article title, content, and summary, you can add unique custom information for specific content types (such as products, services, cases, etc.)These custom fields can be defined in the backend content model settings, including single-line text, numbers, multi-line text, radio buttons, checkboxes, and dropdown selections, among other types.Once defined and added to the content model in an article or product, these custom parameters become part of the content data and can be called and displayed in the front-end template.

Define custom parameter field

On the AnQi CMS backend, the process of defining custom fields begins with the 'Content Model' management.You can edit existing models (such as article models, product models) or create new content models.In the model editing interface, there is an "content model custom field" area.Here, you can add new fields and specify the "parameter name" (the Chinese name displayed to the editor in the background, such as "article author"), and the "field name" (the actual English field name used in the template, such asauthor), as well as field type, whether it is required, and default value. This "call field" is the key identifier we use to obtain the value of the custom parameter in the template.

UsearchiveParamsLabel to get custom parameters

In the AnQi CMS template,archiveParamsThis label is specifically designed to retrieve custom parameters of articles. This tag allows you to get all custom parameters of the current article or a specified article.

archiveParamsThe basic syntax of tags is:{% archiveParams 变量名称 with id="文档ID" sorted=true %}.

Among them,变量名称Is the name you define for the parameter set you obtained, for exampleparams.idThe parameter is used to specify which custom parameter to obtain for the document; if omittedidIt will default to getting the parameters of the document currently displayed on the page.sortedThe parameters are very critical as they determine the structure of the returned data.

Whensortedis set totrue(This is also the default value),archiveParamsIt will return an ordered array of objects. Each element of the array represents a custom field, includingName(parameter name, that is, the Chinese name set in the background) andValue(Parameter value). This method is suitable for scenarios where you want to iterate and display all custom parameters.

The following is an example code for iterating and displaying all custom parameters.

{# 假设这是在文档详情页,或者通过id="指定文档ID"获取 #}
<div>
    {% archiveParams params with sorted=true %}
    {% for item in params %}
    <div>
        <span>{{item.Name}}:</span>
        <span>{{item.Value}}</span>
    </div>
    {% endfor %}
    {% endarchiveParams %}
</div>

This code block will traverseparamsthe array and display the parameter name and corresponding value for each custom parameter.

Directly retrieve a specific custom parameter

In addition to iterating over all custom parameters, Anqi CMS also provides two more direct ways to retrieve the values of specific custom parameters.

The first method is to usearchiveParamsthe tag and assignsortedthe parameter tofalseIn this mode,archiveParamsIt will return an unordered map object, you can directly access it through the custom field "调用字段" (FieldName)NameandValue.

For example, if you define a field namedauthorThe custom field (called field), you can get its value like this:

{# 获取指定文档ID的参数,并以map形式返回 #}
<div>
    {% archiveParams params with id="1" sorted=false %}
        {# 假设存在名为 "author" 和 "version" 的自定义字段 #}
        <div>作者:{{params.author.Value}}</div>
        <div>版本:{{params.version.Value}}</div>
    {% endarchiveParams %}
</div>

This approach is suitable when you know exactly which custom fields you want to retrieve and want to access their values directly.

The second approach is more concise and is done directly byarchiveDetailTag to get the value of a specific custom field. If your custom field is defined in the background with a clear "call field", you can use that call field asarchiveDetailin the tag as the call field.nameThe value of the parameter, to directly obtain its content.

For example, if you have a field calledauthorcustom parameter, you can display it like this:

{# 直接通过archiveDetail标签获取名为"author"的自定义字段值 #}
<div>文章作者:{% archiveDetail with name="author" %}</div>

This method is very suitable for directly inserting a small amount of specific custom parameters for display on the article detail page, the code is more concise and clear.

Application scenarios and **practice

In website operations, custom parameter fields can greatly enrich your content display.For a product page, you can customize fields such as "specifications", "model", "origin", "warranty period", and so on.For the service page, you can add 'service process', 'service cycle', etc.

When displaying these parameters in the template, it is recommended that you:

  • Back-end Naming ConventionsWhen defining custom fields in the back-end, make sure to use meaningful English field names for the 'invoked fields' to facilitate the understanding and use by front-end template developers.
  • Front-end Style AdaptationPlease note that regardless of the method used to obtain the parameter value, it is important to beautify it with CSS styles to keep it consistent with the overall design style of the website and enhance the user experience.
  • Conditional judgmentIn some cases, custom parameters may not be filled in for all articles. When displayed in the template, it is appropriate to use{% if %}tags for judgment to avoid displaying empty values.

By using the above method, you can flexibly and efficiently display custom parameter fields of articles on the Anqi CMS website, thereby creating a content-rich and powerful website.


Frequently Asked Questions (FAQ)

Q1: I defined a custom parameter field, but it does not display on the article detail page, why is that?A1: Please check the following aspects:

  1. Is the field defined correctly in the background content model?Ensure that the "reference field" is in English and free of spelling errors.
  2. Did you fill in the value of this custom field while editing the article?Only fields with values filled in will be displayed on the front end.
  3. Are the correct template tags and field names used in the template?For example, if you usearchiveParamsEnsureitem.Nameanditem.Valuethe call is correct; if you usearchiveDetailto directly retrieve, make surename="您的调用字段"is correct.
  4. Have the caches been cleared?Try to clear the system cache in the 'Update Cache' function in the background.

Q2:archiveParamsin the labelsorted=trueandsorted=falseWhat are the differences, how should I choose?A2: Whensorted=truethen,archiveParamsReturn an ordered array, suitable for when you want to iterate over all custom parameters and display them one by one, or when you are unsure about the custom parameters.For example, display the complete specification list of a product. Whensorted=falseIt returns an unordered map, you can directly access the value of a specific parameter through the field name (in English).This approach is suitable for the scenario where you already know which specific custom parameters to display and want to directly obtain their values without the need to traverse, the code will be more concise.

Q3: Can the value of a custom field be an image or complex HTML content? If so, how can it be displayed correctly in the template?A3: The custom field types of AnQi CMS include single-line text and multi-line text, the multi-line text editor supports rich text editing, so it can include HTML content and even images. When you get the custom field values containing HTML or image addresses through template tags, you may need to use|safeA filter to ensure that content is rendered in its original HTML form rather than escaped as plain text. For example:<div>产品特性:{{item.Value|safe}}</div>. For image URLs, you can use them directly as<img>label'ssrcProperty value.

Related articles

How to display a list of recommended articles related to the current article content, supporting keyword search or manual association?

As an experienced CMS website operation person in the security industry, I know that high-quality content and accurate recommendations are important for improving user experience and website SEO.In the article detail page, effectively displaying recommended articles related to the current content can not only extend the user's visit time and reduce the bounce rate, but also optimize and improve the page weight and crawling efficiency through internal links.AnQi CMS provides flexible tags, supporting us to build this recommendation list through keywords or manual methods.### Implementing related article recommendations in AnQi CMS AnQi CMS uses a powerful template tag system

2025-11-06

How to get the title, link, and thumbnail of the previous and next articles of the current article?

As an experienced website manager familiar with the operation of Anqi CMS, I fully understand the importance of the details of content presentation to user experience and the overall performance of the website.The front and rear navigation function of the article detail page can not only effectively guide users to continue browsing and reduce the bounce rate, but also is an effective means to enhance the relevance between pages and optimize the internal link structure.An enterprise CMS provides a concise and efficient template tag, allowing us to easily achieve this function.--- ### Enhance Content Coherence: Implement Previous and Next Article Navigation in AnQiCMS In Website Content Operation

2025-11-06

How to implement complete pagination functionality for the article list in AnQiCMS template?

As an expert deeply familiar with the operation of AnQiCMS, I know that a smooth, user-friendly website experience is crucial for attracting and retaining users.The pagination feature of a content list is the cornerstone of any content-intensive website, not only optimizing the user's browsing experience, but also an important aspect of search engine optimization.In AnQiCMS, achieving complete pagination for the article list is efficient and flexible through its powerful template tag system.

2025-11-06

How to use the `archiveList` tag to get the article list and support sorting by ID, views, or custom sorting?

As an experienced CMS website operation person, I know that efficient content management is crucial for attracting and retaining users.The template tag system provided by AnQi CMS is its strong point, among which the `archiveList` tag is the core of daily content display.It can help us flexibly extract articles, products, and other content from the database and sort and display them in the way we want.

2025-11-06

How to build a list page of articles with filtering conditions, such as filtering by custom properties?

As an experienced CMS website operation personnel of an enterprise, I know how to meet user needs through refined content presentation.Build a list page of articles with filtering conditions, especially on custom attributes, is an important means to enhance user experience and help users quickly find the information they need.AnQi CMS, with its flexible content model and powerful template tags, makes this process efficient and intuitive.Build a list page of articles filtered by custom attributes, mainly involving the following core stages: first, define and configure these custom attributes in the background management system; next,

2025-11-06

How to display the Tag list of articles in AnQiCMS template and generate links for each Tag?

The generation and display of article Tag list and its links in AnQiCMS template As a website operator who deeply understands the operation of AnQiCMS and has a profound understanding of content operation, I know that article tags (Tags) play a core role in improving content discoverability, optimizing user experience, and strengthening website SEO.Tags can not only help readers find related content quickly, but also provide more rich semantic information for search engines.This article will detail how to efficiently display the tag list in AnQiCMS templates

2025-11-06

How to get the detailed information of a specific Tag, such as Tag name, description, index letter, and Logo?

As an experienced CMS website operator, I am well aware of the importance of content tags (Tags) in website content management and SEO optimization.They can not only help us organize content more flexibly and improve user experience, but are also one of the key factors for search engines to understand the structure of website content.Today, I will delve deeply into how to obtain and display detailed information of specific tags in the Anqi CMS template, including tag names, descriptions, index letters, and Logos, to achieve a more refined front-end display.###

2025-11-06

How to display all articles under a specified Tag with pagination support?

As an experienced security CMS website operations manager, I know that high-quality and easily understandable content is crucial for user experience.Today, we will discuss how to implement the article list display under specified tags in AnQi CMS, and add practical pagination functions. This is of great importance for improving user browsing experience and website SEO. ### Understanding the Importance of Tag Pages In Anqi CMS, tags (Tags) are a powerful content organization tool.They allow us to associate the content of different categories even different models through common themes or keywords

2025-11-06