In Anqi CMS, managing and displaying content, the article detail page is undoubtedly the core battlefield for users to obtain information.In addition to basic elements such as the article title and main content, we often need to display some personalized information on the detail page, such as the author of the article, source of content, product specifications, and location of release.This information is called "Custom Parameters" in the Anqi CMS, which can greatly enrich the dimensions of content and meet the personalized needs of different business scenarios.
The Anqi CMS provides a very flexible way to define and display these custom parameters, allowing website operators to easily customize the content display of article detail pages according to their actual needs.Below, let's take a look together at how to operate to make these custom parameters elegantly displayed on the article detail page.
Step 1: Define your custom parameters in the backend
In AnQi CMS, custom parameters are defined through the "Content Model".The content model is like the skeleton of content, determining which fields a type of content (such as 'article' or 'product') can have.
- Enter content model managementFirst, log in to your security CMS backend management interface, navigate to the "Content Management
- Select or create a modelThe translation is: Usually, you may already be using the system's built-in 'Article Model' or 'Product Model'. You can choose to edit an existing model or create a new one based on your needs.
- Add Custom FieldsIn the selected model, you will see the 'Content Model Custom Fields' area. Here, click Add Field to name your custom parameters.
- Parameter nameThis is the readable name used in the background management interface and front-end template to display the parameter, such as 'Article Author', 'Content Source'.
- Call fieldThis is the field name stored in the database, and also the unique identifier referenced in the template.To maintain standards and ease of recognition, it is recommended to use concise English letters, such as 'author' representing the author, and 'source' representing the source.
- field typeSelect the data type you want to store, and Aqiy CMS provides various types such as single-line text, numbers, multi-line text, single selection, multiple selection, dropdown selection, and even image groups.
- Other SettingsConfigure as needed whether it is required, default value, etc.
After adding custom fields, remember to save the content model settings.
Second step: Fill in custom parameters when publishing or editing articles
When you have defined the custom parameters in the content model, these custom fields will appear on the article editing page when you publish or edit articles belonging to that model.
- Publish/Edit ArticleGo to “Content Management” -> “Document Management”, select “Publish Document” or edit an existing article.
- Select the category it belongs toEnsure that the 'Category' you select is associated with the content model you configured custom parameters for in step one.
- Enter the parameter valueIn the 'Other Parameters' section of the article editing interface, you will see the custom fields that you have just defined.Here, enter the corresponding values for each parameter.For example, enter the author's name in the "Article Author" field and the source website in the "Content Source" field.
After saving the article, these custom parameter values are successfully stored.
Step 3: Display custom parameters in the article details page template
Now, a critical step: how can you obtain and display these custom parameters in the article detail page template on your website's frontend?The Anqi CMS provides powerful and flexible template tags, which can easily achieve this goal./template/您的模板目录/archive/detail.htmlor in the custom template file you set for articles in the background.
We will introduce two commonly used methods for obtaining and displaying custom parameters, you can choose the most suitable one according to your actual needs:
Method one: Directly access via field name (suitable for known and few specific parameters)
If you only need to display a few known custom parameters, such as "author" and "source", and you already know their "field names" defined in the content model (such asauthorandsourceThen it is the simplest way to directly access the field by name.
You can usearchiveDetailTag, and specifynameIt is the name of the "invoking field" for custom parameters.
Code example:
{# 假设自定义参数的调用字段为 author 和 source #}
<div class="article-meta">
{% set articleAuthor = "" %}
{% set articleSource = "" %}
{# 获取作者 #}
{% archiveDetail authorName with name="author" %}
{% set articleAuthor = authorName %}
{% endarchiveDetail %}
{# 获取来源 #}
{% archiveDetail contentSource with name="source" %}
{% set articleSource = contentSource %}
{% endarchiveDetail %}
{% if articleAuthor %}
<span>作者:{{ articleAuthor }}</span>
{% endif %}
{% if articleSource %}
<span>来源:{{ articleSource }}</span>
{% endif %}
</div>
Explanation:
{% archiveDetail authorName with name="author" %}This line of code will try to find the value of the called field named from the custom parameters of the current article.authorand assign it to the variable namedauthorName.- Pass
{% set ... %}and further assign it toarticleAuthorandarticleSourceVariables are used for more convenient conditional judgments.{% if ... %}), to avoid directly outputting empty content when the parameter does not exist. <span>作者:{{ articleAuthor }}</span>: If the author information is obtained, it will be displayed.
This method is simple and direct, with clear code, and is very suitable for scenarios where specific custom parameters are displayed at fixed positions on article detail pages.
Method two: Loop through all custom parameters (suitable for scenarios where the number of parameters is dynamic and needs to be displayed uniformly)
If you have a large number of custom parameters, or you want to display all custom parameters in a list format, or you are unsure about the name of each parameter's "calling field", then usearchiveParamslabel combined withforLoop through all parameters will be more flexible.
archiveParamsThe tag will get all custom parameters of the current article and organize them into an array object for you to loop through.
Code example:
<div class="article-custom-params">
<h4>文章附加信息:</h4>
<ul>
{% archiveParams params %}
{% for item in params %}
<li>
<strong>{{ item.Name }}:</strong> <!-- 显示“参数名” -->
<span>{{ item.Value | safe }}</span> <!-- 显示“参数值”,注意safe过滤器 -->
</li>
{% endfor %}
{% endarchiveParams %}
</ul>
</div>
Explanation:
{% archiveParams params %}This tag will retrieve all custom parameters of the current article and store the results.paramsthe variable.{% for item in params %}We loop through.paramsthe array. In each iteration,itemThe variable represents a custom parameter object.{{ item.Name }}: It will display the 'parameter name' (such as 'Article Author') you set in the background.{{ item.Value }}: It will display the specific value filled in for this custom parameter (such as 'Zhang San').| safeThis filter is very important! If your custom parameter value may contain HTML content (such as bold, links, etc. that you have entered in the 'Multi-line text' field in the backend), use| safeIt can ensure that these HTML content is correctly parsed by the browser rather than displayed as plain text.
The benefit of this method is that the template code does not need to be modified regardless of how many custom parameters you add in the background.It will automatically adapt and display all filled parameters.item.Nameoritem.ValuePerform conditional judgments to implement more complex display logic.
Flexible application, enhance content value
By following these steps, you can flexibly retrieve and display custom parameters of the article on the detail page of the Anqi CMS according to your actual needs.Whether it's simple author information or a complex product specification list, the flexible content model and powerful template tags of Anqi CMS can lend you a helping hand.Effectively utilizing these features not only makes your website content more rich and personalized, but also greatly enhances user experience and the effectiveness of content marketing.
Common Questions (FAQ)
Q1: I have set custom parameters and filled in the content in the background, but the article detail page does not display. Why is that?A1: There are several