How to display the custom parameter list in the article content on the front page?

Calendar 👁️ 65

AnQiCMS as an efficient and customizable content management system provides powerful content model features, allowing us to add various custom fields to articles according to different business needs.These custom parameters not only make the article content more rich and structured, but also allow for personalized display on the front page, greatly enhancing the flexibility and user experience of the website.

Today, let's delve into how to flexibly display these custom parameter lists in the AnQiCMS front page of the article.

Backend preparation: Define custom parameters

In AnQiCMS, custom parameters are closely related to the 'content model'. This means that you first need to define these parameters for your content model in the background.

Log in to the AnQiCMS backend, navigate to the 'Content Management' menu under 'Content Model'.Here, you can see the built-in "article model", "product model", etc., and you can also create your own content model.Select the model you need to add custom parameters, click 'Edit'.

In the model editing interface, you will find a section named "Content Model Custom Fields".This is where we define various personalized parameters. Each field is like adding a unique 'label' and 'attribute' to the content, allowing you to specify parameter names (for backend management and identification), calling fields (for frontend template calls), field types (such as single-line text, numbers, multi-line text, single selection, multiple selection, dropdown selection), and whether it is required and default values, etc.For example, you can add a custom field named 'Article Source' to the 'Article Model', or add 'Product Size', 'Color Options', and so on to the 'Product Model'.

Once you define and save custom fields here, they are just like the article content itself and can be called and displayed in the front-end template.

Front-end display: Core tagsarchiveParamsapplication

Now, we have defined the data structure of the backend, and the next step is to display this information in the front-end template. AnQiCMS provides a special tag for getting custom parameters of articles:archiveParams.

This tag is usually used on the article detail page, to get all the custom parameters associated with the current article. Its basic usage is to define it as a variable, and then throughforLoop through this variable to display the name and value of each parameter.

The basic code structure will be like this:

{% archiveParams params %}
    {% for item in params %}
        <div>
            <span>{{ item.Name }}:</span>
            <span>{{ item.Value }}</span>
        </div>
    {% endfor %}
{% endarchiveParams %}

In this code block:

  • {% archiveParams params %}Store all custom parameters of the current article in a namedparams.
  • {% for item in params %}Loop through thisparamsarray,itemRepresents a custom parameter in each loop.
  • {{ item.Name }}Will output the custom parameter name set in the background (usually Chinese, such as "article source").
  • {{ item.Value }}It will output the actual content value of the custom parameter (such as "AnQiCMS Official Blog").

archiveParamsTags will be returned in the order you set in the background, which is achieved bysorted=trueParameter control, but due tosorted=trueIt is the default behavior, usually it can be omitted. If you want to get the custom parameters of a specified article, rather than the article on the current page, you can throughidSpecify the article ID with parameters, for example:{% archiveParams params with id="123" %}.

Another shortcut method:archiveDetailDirect call

If you are only concerned with a specific custom parameter and you already know its field name (i.e., the 'field name' you set in the background, usually in English), then you can usearchiveDetailTag to directly obtain its value without traversing the entire parameter list.

For example, assume you have a custom field whose calling field name isauthor_sourceYou can directly get its value like this in the template:

<div>文章来源:{% archiveDetail with name="author_source" %}</div>

Or, if you want to assign its value to a variable first and then use it, you can do it like this:

{% archiveDetail articleSource with name="author_source" %}
<div>文章来源:{{ articleSource }}</div>

This method is suitable when you only want to display a few specific custom parameters, and you already know their field names, making the code more concise.

Optimization and注意事项

In the actual front-end display, there are some details and optimization techniques that can help you present these custom parameters better:

  1. Style control: item.Nameanditem.ValueThe output is usually just plain text. To make them look more beautiful on the front end, you may need to write CSS styles yourself to beautify<div>/<span>such as the display of HTML elements.

  2. Null value handling:Sometimes, custom parameters may not be filled in. To avoid displaying blank or unnecessary titles on the front end, you can useifLabel for judgment:

    {% archiveParams params %}
        {% for item in params %}
            {% if item.Value %} {# 仅当有值时才显示 #}
                <div>
                    <span>{{ item.Name }}:</span>
                    <span>{{ item.Value }}</span>
                </div>
            {% endif %}
        {% endfor %}
    {% endarchiveParams %}
    
  3. Rich text/Markdown content:If your custom parameter type is multiline text and you want to support rich text or Markdown formatting, then in the outputitem.Value

Related articles

How to use the `pagination` tag to build standard pagination navigation in the template?

When the content of a website becomes richer, a clear and efficient pagination navigation system is crucial for improving user experience.The AnQiCMS template system provides a powerful `pagination` tag that allows us to easily build standard, beautiful pagination navigation.Next, we will delve deeper into how to use this tag in templates.

2025-11-07

How to display the number of comments for each article on the article list page?

In website operation, the article list page is not only the entrance of content, but also a window for users to understand the activity level of the website.When users see that every article is accompanied by a comment count, this not only effectively enhances the interactivity and attractiveness of the article, but also brings positive social proof to the website, encouraging more readers to participate in discussions.For users who use AnQiCMS, displaying the number of comments for each article on the article list page is a very direct and practical feature.

2025-11-07

How to ensure that the website displays a custom prompt to users when it is in "shutdown" status?

In website operation, we sometimes encounter situations where we need to temporarily close the website, such as for system maintenance, major upgrades, data migration, or dealing with unexpected security events.For any reason, directly allowing users to access a blank page or an error page will severely affect user experience and even damage the brand image.At this time, it is particularly important to clearly display a friendly prompt message to visitors.

2025-11-07

How to call and display the independent domain of the website backend configured in the template?

In the flexible content management system of AnQiCMS, site operators often need to display some key background configuration information in the website template according to business needs.Among the settings such as 'Background Independent Domain', it not only concerns the security of the system, but may also need to be displayed on the website front-end in certain scenarios, such as being used as a quick access entry for internal personnel, or for information explanation on specific pages. Today, let's delve into how to cleverly call and display the independent domain you have configured in the AnQiCMS template.###

2025-11-07

How to truncate the title or abstract of an article and display it with an ellipsis?

In website content operation, titles and summaries are important elements to attract visitors to click and learn more details.Especially on list pages, recommendation positions, or the homepage, the limited space requires us to refine and cut these contents.To maintain the neatness and aesthetics of the page while fully conveying the core information, it is a common optimization strategy to truncate overly long article titles or summaries and end them with an ellipsis "..."}AnQiCMS (AnQi CMS) provided us with flexible and powerful tools to meet this requirement.

2025-11-07

How to use logical tags like `if` and `for` in templates to control conditional and repeated display of content?

In website content management, displaying dynamic and diverse content is the key to improving user experience and website attractiveness.AnQiCMS (AnQiCMS) provides a powerful template system, drawing inspiration from the Django template engine syntax, allowing you to easily control the display of content through logical tags.Among them, the `if` tag is used for conditional judgment, while the `for` tag is used for loop iteration, they are the foundation for building flexible and variable web pages.

2025-11-07

How to safely display rich text content containing HTML tags on the front-end page?

In website operation, we often need to display rich content that includes images, links, bold text, and so on, which is known as rich text content.But it is a practical and careful task to safely display these rich text with HTML tags on the front-end page.AnQi CMS as an efficient content management system, fully considers this point, and provides us with a clear solution.

2025-11-07

How to dynamically display the current year or current time in a template?

In website operation, we often need to dynamically display the current year or time, such as displaying the latest copyright year at the bottom of the website, or marking the generation time of the page accurately in articles.AnqiCMS provides flexible and powerful template functions, making these operations very simple.Next, we will discuss how to implement this requirement in the AnqiCMS template.

2025-11-07