How to ensure that custom parameters set in the AnQiCMS backend can be displayed in the front-end template?

Calendar 👁️ 72

The AnQi CMS endows content management with exceptional flexibility, and the custom parameter function is the key to meeting the needs of personalized content display.How to accurately present the unique parameters set for articles, products, or category content models on the website front-end template is a concern for many users.This article will elaborate on this process, helping you fully utilize the powerful customization capabilities of Anqi CMS.

Learn the mysteries of custom parameters

First, ensure that custom parameters can be displayed in the frontend template, the core lies in the backend content model definition and data entry.In the Anqi CMS backend management interface, you need to go to the "Content Management" section, click on the "Content Model".Whether it is the built-in article model, product model, or a custom model created by yourself, you can add 'Content Model Custom Field' in its settings.

When adding custom fields, there are several key pieces of information to keep in mind: 'Parameter name' is the name of this field displayed to you in the background, convenient for management;The 'invoking field' is truly important part, it determines the name used to access the parameter in the template, and this name is usually recommended to use letters, and keep it unique.In addition, the 'field type' determines the input form of the parameter, such as single-line text, multi-line text, numbers, single selection, multiple selection, or drop-down selection, which also affects how you process the data after obtaining it in the front-end template.It is equally important to set appropriate 'default values' for these fields, which can provide alternative content when you do not manually fill in the parameters.

For example, if you add a custom field named "article author" to a "article model" and set its "field call" toauthorSo when you publish articles, you can fill in author information for each article.

Let parameters shine in front-end templates.

Once you have properly configured the custom parameters and entered the content in the background, the next step is to present it on the website front end.The AnQi CMS template engine provides a simple and powerful way to read these custom data.

1. Directly call a single custom field

If you clearly know the name of a custom field's 'call field' and the field stores a single value (such as the author of an article, product model), you can directly use the double curly bracket syntax to call it. The most common way is to usearchiveDetailThe tag, which is specifically used to retrieve detailed data of the document, including its custom parameters.

For example, if you want to display the settings you made before on the article detail page.authorField, you can write the template code like this:

<div>文章作者:{% archiveDetail with name="author" %}</div>

Or, if the current page context is already a document (archive) itself, you can also access it directly through object properties:

<div>文章作者:{{ archive.author }}</div>

Herename="author"orarchive.authorAll point to the "call field" name set in the background content modelauthorthe parameter.

2. Loop through all custom fields.

Sometimes, you may want to dynamically display all the custom parameters of an item in an area without listing them one by one in the template. At this point,archiveParamsThe tag comes in handy. It can retrieve all custom parameters of the current document (or a document specified by ID) and return them as an array, where you can iterate over this array to display the name and value of each parameter.

This is an example of a template code that iterates and displays all custom parameters:

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

In this example,item.NameIt will display the parameter name you set in the background (for example, "Article Author") whileitem.ValueIt will display the specific content of the parameter.

3. Flexibly handle complex data types

The types of custom fields are diverse, and they also need to be flexibly handled after acquisition:

  • Multi-line text or rich text editor content:If your custom field is multiline text or a rich text editor content (such as a Markdown editor) that may contain HTML tags. In order for this content to be rendered correctly instead of displaying the raw code, you need to use|safeFilter. If the Markdown editor is enabled and the content is in Markdown format, you may also need|renderThe filter will first convert it to HTML.

    <div>文章摘要:{{ archive.abstract|render|safe }}</div>
    
  • Multiple image upload, multiple selection, drop-down selection, etc:When the custom field type allows multiple selections (such as image groups, multiple choices), Anqi CMS usually returns it as an array or slice. You need to useforLoop to iterate through these values.

    For example, if you have a variable namedproduct_imagesCustom field for uploading multiple product images:

    {% archiveDetail productImages with name="product_images" %}
    <ul class="product-gallery">
      {% for img in productImages %}
      <li><img src="{{ img }}" alt="产品图片" /></li>
      {% endfor %}
    </ul>
    {% endarchiveDetail %}
    
  • Attribute access of specific field: archiveParamsTags also support throughsorted=falseThe parameter is obtained in the form of a Map (key-value pairs), if you need to access a specific field accurately,NameorValuethis method will be more direct.

    {% archiveParams params with sorted=false %}
        <div>作者姓名:{{ params.author.Value }}</div>
        <div>联系电话:{{ params.phone_number.Value }}</div>
    {% endarchiveParams %}
    

    Hereparams.author.Valuedirectly obtained the field calledauthorthe value.

By using the above method, you can flexibly and accurately present the custom parameters set in the Anqi CMS backend in the website front-end template, bringing great convenience and extensibility to your website content management.


Frequently Asked Questions (FAQ)

1. I have set custom parameters in the background, but they do not show up in the front-end template. What could be the reason?The most common reason is that the 'call field' name has been entered incorrectly in the template. Please carefully check the custom field 'call field' name in the background content model to ensure that the case is matched perfectly. In addition, also check if you have used the correct tags (for example, in the document detail page, you should use')archiveDetailorarchiveParams), as well as whether the data has been entered into the custom field of this content.

2. How to display rich text content (such as Markdown or HTML) as raw code on the front end instead of formatted styles?This is because the template engine defaults to escaping output content to prevent potential security issues. If your custom fields contain HTML or Markdown content, you need to add it when calling the template.|safeThe filter tells the template engine that this is safe content and does not need to be escaped. If the content is Markdown format and needs to be rendered on the front end, it may also be necessary|rendera filter such as{{ archive.my_rich_text_field|render|safe }}.

How to determine if a custom field exists in a front-end template and display a default placeholder when there is no content?You can useifCondition judgment to check if the field contains content. For example,{% if archive.my_custom_field %}{{ archive.my_custom_field }}{% else %}暂无内容{% endif %}. For fields with default values, you can also take advantage ofdefaulta filter such as{{ archive.my_custom_field|default:"未填写" }}, so it will display 'Not filled' when the field is empty.

Related articles

How to implement keyword batch replacement in AnQiCMS and affect the display of front-end content?

It is crucial to maintain the accuracy, timeliness, and brand consistency of content in website operations.Especially when the amount of website content is large, if you need to make global changes to specific keywords or phrases, manual operation will be a huge project that is time-consuming and labor-intensive.AnQiCMS (AnQi CMS) exactly discerned this need, providing a powerful feature named 'Full Website Content Replacement' to help users efficiently manage and update website content, thereby affecting the display effect of front-end content.Why do we need to batch replace keywords? With the development of the enterprise, product updates, or market strategy adjustments

2025-11-07

How to display the list of internal titles (H1, H2, etc.) of the article content on the article detail page?

In Anqi CMS, in order to enhance the reading experience of long articles and the page SEO effect, we usually hope to display a list of internal titles (H1, H2, etc.) on the side or above the article content on the article detail page, which is what we usually call the article catalog or navigation.This makes it convenient for readers to quickly jump to the chapters of interest, and also helps search engines better understand the structure of the article. The AnQi CMS provides a very convenient way to implement this feature, the core lies in its powerful template tags and content field extraction capabilities.###

2025-11-07

How to display the current model name or URL alias in AnQiCMS?

In website content management, we often need to make the various parts of the website adapt and display information intelligently, one common requirement being how to dynamically display the name or URL alias of the current content model on the front-end page.This is crucial for improving user experience, optimizing search engine performance, and flexible management of website structure.AnQiCMS as an enterprise-level content management system provides a very flexible and powerful template tag function, making it intuitive and efficient to achieve this goal.

2025-11-07

How to remove HTML tags in AnQiCMS template and display only plain text content?

When using AnQiCMS for content creation and display, we often need to flexibly control the presentation of content on the front end.Sometimes, the article or product description may contain rich HTML tags, which are used to provide beautiful layout on the detail page.

2025-11-07

How to convert a timestamp to a specified date format and display it in the AnQiCMS template?

In Anqi CMS template design, we often encounter the need to display timestamp data in a human-readable date format.Whether it is the publication time of the article, the update date of the content, or the record of user activities, this data is usually stored in the database in the form of timestamps.It is particularly important to master how to convert timestamps to the specified date format in templates so that website visitors can clearly and intuitively understand this information.

2025-11-07

How to display the category thumbnail and name in the article list?

## SecureCMS: Display category thumbnails and names elegantly in article lists In website operation, the article list page is an important entry point for users to browse content and discover information.A beautifully designed, informative list of articles can not only enhance user experience but also effectively guide users to delve deeper into reading.The traditional article list may only display titles, publication time, summaries, and other information, making it somewhat monotonous.

2025-11-07

How to automatically parse the URL string in the text of AnQiCMS to make it clickable?

In daily content operation, we often need to embed various external or internal links in text content such as articles, product descriptions, and even category summaries.However, manually converting each plain text URL string into a clickable HTML link is not only time-consuming and labor-intensive, but also prone to link errors due to negligence, affecting user experience and search engine optimization.

2025-11-07

How to display the number of views and comments on articles in AnQiCMS templates?

In website operation, the number of page views and comments on articles is an important indicator of the popularity of content and user engagement.AnQiCMS provides flexible template tag functions, allowing you to easily display these key data on the website front end, thereby better attracting visitors and enhancing content value.

2025-11-07