When using AnQi CMS to manage your website content, you may find that relying solely on default fields such as title, content, and abstract is not enough to fully meet the needs of personalized display.For example, you would like to display information such as 'author' and 'source' on the article detail page, or show specific parameters such as 'material' and 'size' on the product page.The Anqi CMS provides powerful custom parameter functionality, allowing you to easily add, manage, and display these personalized information for different types of documents (such as articles, products).

This article will introduce in detail how to obtain and display custom parameters of specified documents in Anqi CMS, such as authors, sources, etc., to help you create a more rich and customized content display.

One, configure custom parameters and enter content in the background

To obtain and display custom parameters, you first need to configure them in the Anqi CMS backend. This process is divided into two steps: defining the parameters and then entering the values of these parameters for the document.

1. Define custom fields of the content model

Custom parameters are associated with the 'Content Model'. Each content model (such as 'Article Model', 'Product Model') can have its own unique custom fields.

  • Enter content model management:Log in to the AnQi CMS backend and navigate to“Content Management”Menu, then click“Content Model”.
  • Select or create a model:Here, you can choose to edit an existing content model (such as 'Article Model') to add new fields, or create a new content model.
  • Add custom field:In the selected content model editing page, find“Content model custom field”the area, click “Add Field”. You will see the following key settings:
    • Parameter name:This is the Chinese name displayed on the backend interface for operators, such as "article author", "source of content".
    • Call field:This is the unique identifier used to call this parameter in the front-end template, it must use letters, it is recommended to use camel case or lowercase underscore naming, for exampleauthor/source/materialThis field name is crucial, it will be used when the front-end is called.
    • Field type:Choose the appropriate field type according to the data you need to store, such as 'Single-line text' (for authors, sources), 'Multi-line text' (for longer introductions), 'Number', 'Single choice', 'Multiple choice', or 'Dropdown selection', etc.
    • Mandatory?:Determine whether the field is required based on business requirements.
    • Default:If the field has common values, you can set a default value.
  • Save configuration:After completing the field settings, be sure to click the save button to make the changes take effect.

2. To enter custom parameter values for the document

After defining custom fields for the content model, you can fill in specific content for these fields when publishing or editing the document corresponding to the model.

  • Enter the document editing interface:Navigate to“Content Management”, click“Publish document”Or edit an existing document.
  • Fill in custom parameters:Below the document editing page, there will be a:“Other Parameters”The collapsed area. Expand this area to see the custom fields defined for the content model, as well as the corresponding input boxes or options.Here, you can fill in information such as 'article author', 'content source', etc. for the current document.
  • Save the document:After filling in, save the document. The values of these custom parameters will be stored with the document.

Chapter 2: Retrieve and display custom parameters in the front-end template

After configuration and entry are completed, the next step is how to display these custom parameters on the website front-end page (usually the document detail page).Aq CMS provides powerful template tags, making this process very flexible.

Generally, you need to add the following code in the directory under your template.{模型table}/detail.htmlfor examplearticle/detail.htmlorproduct/detail.htmlAdd the following code to the file.

1. Directly call the specified custom parameters (recommended for simple scenarios)

For specific fields like 'author' or 'source' that are displayed only once on the page, the most direct method is to usearchiveDetail.

Assuming you have defined the "author" (call field asauthor) and "source" (call field assource) two custom fields.

{# 在文档详情页,您可以直接使用 archive 对象来调用自定义字段 #}
<p>作者:{{ archive.author }}</p>
<p>来源:{{ archive.source }}</p>

{# 或者,使用 archiveDetail 标签,这在当前页面不是文档详情页,但您知道文档ID时非常有用 #}
<p>作者:{% archiveDetail with name="author" %}</p>
<p>来源:{% archiveDetail with name="source" %}</p>

{# 如果自定义参数的内容是富文本或 Markdown 格式,需要加上 |safe 过滤器,Markdown 内容还需 |render 过滤器 #}
<div class="introduction">
    产品简介:{{ archive.introduction|render|safe }}
</div>

Description:

  • In the document detail page, the system usually automatically provides a variable namedarchivewhich contains all the information of the current document, including custom parameters. You can access{{ archive.调用字段名 }}in the form of direct access.
  • {% archiveDetail with name="调用字段名" %}This approach is more general, regardless of whether the current page is directly a document detail page, as long as the system can identify the document context or you specify a document ID, it can obtain the data.
  • |render|safeIf your custom field type is a rich text editor, and the content may contain HTML tags or Markdown syntax, in order for this content to be displayed correctly rather than as plain text output, you need to add|safeFilter. If the Markdown editor is enabled at the same time, it needs to be enabled first|renderthen|safe.

2. Loop through all custom parameters (for dynamic display)

If you want to dynamically display all the custom parameters of a document in an area, for example, to display all specifications uniformly on a product detail page, thenarchiveParamsThe label will be very convenient. It will return a list of custom parameters, and you can loop through them to display their names and values.

<div class="custom-parameters">
    <h3>详细参数</h3>
    {% archiveParams params %}
    {% for item in params %}
        <p><strong>{{ item.Name }}:</strong> {{ item.Value|safe }}</p>
    {% endfor %}
    {% endarchiveParams %}
</div>

Description:

  • {% archiveParams params %}It will retrieve all the custom parameters defined in the current document and assign them toparamsVariable.
  • paramsIt is an array object, each element of which containsName(parameter name, such as "article author") andValue(Parameter value).
  • By{% for item in params %}Loop, you can take each parameter name and value one by one to display.
  • Similarly,|safeThe filter is also very important here to prevent the parameter value from containing HTML content that needs to be parsed.

Step 3: Usage Tips and Precautions

  • Call field name consistency:Make sure the name used to define the "call field" in the background is exactly the same as the name you use when calling it in the template (including case).
  • Data type match: When defining field types in the background, please select according to the actual content. For example, if the custom field is a multi-select type, then on the front enditem.ValueMay be a comma-separated string, you may need to perform additional processing (such as using|split:","a filter to convert it into an array and then iterate over it).
  • Template cache:After modifying the template file, if the page does not update immediately, please try to clear the AnQi CMS system cache or browser cache.
  • Style beautification:The above code is just for functional implementation, in actual application, you also need to beautify these custom parameters through CSS to keep them consistent with the overall style of the website.

By using the above method, you can fully utilize the custom parameter function of Anqi CMS to add more dimensions and personalized display to your website content, thereby enhancing user experience and content value.


Frequently Asked Questions (FAQ)

Q1: Why do I not see the custom parameter I set in the background in the "Other parameters" page of the document editing page?A1: Please check if you haveThe content model of the current documentAdded custom parameters. For example, if you are editing an "article", the custom parameters must be defined under the "article model".In addition, make sure to click the save button after defining custom fields, and you may need to refresh the page to display them.

**Q2: When I call a custom parameter in the template, it displays plain text without parsing HTML tags or Markdown content