How to call and display custom field content in the article detail page of AnQiCMS?

Calendar 👁️ 71

In AnQiCMS, managing and displaying content, custom fields play a crucial role, allowing our website to flexibly carry various unique information, not limited to general attributes such as title and content.Whether it is to add detailed technical parameters for product detail pages or to supplement author profiles and external reference links for articles, custom fields can provide strong support.Understand how to call and display these custom fields on the article detail page, which will greatly enhance the richness and customization of the website content.

One of the design philosophies of AnQiCMS is to provideFlexible content modelThis is the basis for the role of custom fields. By customizing the content model, you can define various content types according to business needs and add exclusive fields for each type to meet the personalized display needs of content.

Define and manage custom fields: the foundation of the content model

In the AnQiCMS backend, the management of custom fields is concentrated in the 'Content Model' under the 'Content Management' module.The system provides default "article model" and "product model", you can also create your own content model.Enter any content model and you will find the "Content Model Custom Field" area, where you can add new fields as needed.

Each custom field needs to specify a 'parameter name' (used for display and identification in the background) and a 'calling field' (the actual name referenced in the template). The field types are diverse, including:

  • Single-line text: Suitable for brief text descriptions, such as author names, product models.
  • Number: Ensure the input content is purely numeric, such as prices, inventory.
  • Multi-line text: Suitable for longer text content, such as product features descriptions, author biographies.
  • Single choice/Multiple selections/Drop-down selection: Provides preset options for selection, suitable for standardized data such as product colors, sizes.

Correctly setting the field type and calling the field name is the premise for accurately calling data in the template later.

Call the custom field content in the article detail page.

Once the custom field is defined and content is filled in for a specific article, the next step is to display it in the template.AnQiCMS provides two main ways to call these custom fields: directly calling specific fields and iterating through all fields.

1. Directly call a single custom field

If you know the name of the custom field's "call field" and the field is a single value (such as single-line text, number, or multi-line text), you can use it directlyarchiveDetailLabel to get its value. For example, if you create a namedauthorsingle line text field:

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

Or, you can assign the field value to a variable and then perform subsequent operations, which is very useful when you need to process the value:

{% archiveDetail articleAuthor with name="author" %}
<div>作者名称:{{ articleAuthor }}</div>

In this way, you can accurately display custom information on the article detail page at the specified location.

2. Loop through all custom fields.

When you want to dynamically display all custom fields of an article, or are unsure of the specific names of each field,archiveParamsThe tag is very useful. It retrieves all the custom fields of the current article and provides them as an array (or object) to the template.

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

In this code block,paramsis an array that contains all custom fields, eachitemhasName(parameter name, that is, the Chinese name displayed in the background) andValue(Field value) attribute. This method is especially suitable for product parameter lists or dynamic display of additional information.

3. Handle custom fields of specific types.

Some custom field types require special handling when displayed, such as album or multiple choice fields. Assume you have defined an album field namedarcimagesused for uploading multiple images:

{% archiveDetail arcimages with name="arcimages" %}
<ul class="article-gallery">
  {% for imgUrl in arcimages %}
  <li><img src="{{ imgUrl }}" alt="文章图片" /></li>
  {% endfor %}
</ul>

here,arcimagesIt will return an array of image URL, you canforloop through and display each image.

If the custom field stores rich text content, which may include HTML tags, to avoid these tags being escaped as plain text, you need to use|safeFilter:

{% archiveDetail articleContent with name="自定义富文本字段名" %}
<div>{{ articleContent|safe }}</div>

If a custom field contains Markdown formatted content and you want it to be parsed as HTML, you can use|renderFilter:

{% archiveDetail articleMarkdown with name="自定义Markdown字段名" %}
<div>{{ articleMarkdown|render|safe }}</div>

Little tricks in practice

  • Debugging tool: During development, if you are unsure about the structure or value of custom fields, you can use|dumpa filter to print variable details, for example{{ params|dump }}This will display the variable type and content, helping you quickly locate the problem.
  • Conditional judgmentIn displaying custom fields, it is best to include conditional judgments to prevent unnecessary blank spaces or errors from appearing on the page when fields are empty. For example{% if item.Value %}or{% if arcimages %}.
  • Naming convention: Choose a clear and meaningful "call field" name for custom fields, which will make the template code easier to read and maintain.
  • Filter applicationUse flexible applications of the various filters provided by AnQiCMS (such as|thumbUsed to obtain thumbnails,|truncatecharsUsed to extract text and so on), it can better beautify and process the display effect of custom fields.

By using the above method, you can fully utilize the custom field function of AnQiCMS to build a powerful, content-rich, and highly personalized article detail page of the website, meeting various complex display requirements.


Frequently Asked Questions (FAQ)

1. Why did I add a custom field but nothing is displayed when called in the template?This usually has several reasons:

  • Field name is incorrect: Please check the template inname="自定义字段名称"The part is whether it is consistent with the 'Call Field' name set in the background 'Content Model', including case sensitivity.
  • The content of the article has not been saved.Confirm whether you have filled in the content for this custom field and successfully saved it while editing the article.
  • The field type does not match.For example, if you try to use{% archiveDetail with name="字段名" %}Directly fetching a single value may result in not getting the expected result. For multi-select or group image fields, it is usually necessary to iterate through their content.

How to use different custom fields for different categories of articles?In AnQiCMS, custom fields are bound to the 'content model' rather than 'categories'.This means that all articles belonging to the same content model (such as "article model") will share the custom fields defined under the model.If you need to use completely different custom field sets for articles of different categories, you can consider creating different "content models" and associating different categories with different content models.For example, create a "news model" and a "tutorial model", which can have their own independent custom fields.

My custom field content is HTML code, but it gets escaped when displayed. How to solve this?If your custom field stores HTML code (for example, through a rich text editor), when outputting directly in the template, for safety, AnQiCMS will default to escaping it. In order for these HTML codes to be parsed and displayed correctly by the browser, you need to use|safea filter. For example:{{ archiveContent|safe }}Please note that using|safemeans you trust that the content is safe and will not pose XSS or other security risks.

Related articles

How to get and display the detailed information of a single article in AnQiCMS?

Managing and displaying content in AnQiCMS is one of its core functions.It is crucial to understand how to accurately retrieve and display the detailed content of a specific article when you need to present it to visitors.AnQiCMS provides a直观 and powerful template tag system that allows you to flexibly control the layout and content of the article detail page. ### Overview of AnQiCMS Template System The AnQiCMS template uses syntax similar to the Django template engine.In the template file, you will encounter two main markers: - **Double braces

2025-11-08

How to display all documents under the current category and its subcategories in AnQiCMS template?

In AnQiCMS template design, flexibly displaying content is the key to website operation.When you need to display articles under a category page not only, but also hope to present all subcategory articles together, or display them in a more structured way, AnQiCMS provides powerful template tags to meet these needs.This article will introduce in detail how to implement this feature in your AnQiCMS template.### Understanding AnQiCMS's classification and document mechanism In AnQiCMS, content is usually organized under "document model" and "classification"

2025-11-08

How to filter and display a list of documents in AnQiCMS using custom parameters?

In AnQiCMS (AnQiCMS), when managing and displaying a large amount of content, we often need to go beyond simple categories and tags to achieve more refined content filtering.For example, a real estate website may need to filter listings by "type", "area", and "price range";An e-commerce website may need to filter products by color, size, and brand.AnQiCMS provides a powerful custom parameter feature, making it very intuitive and efficient to implement this advanced filtering.Below, we will gradually understand how to use AnQiCMS

2025-11-08

How to display a list of articles published by a specific author in AnQiCMS?

In AnQiCMS, efficiently managing and displaying content is the core of website operation.Sometimes, you may need to display all the articles published by a specific author, such as creating an author column, a team member introduction page, or a personal portfolio.AnQiCMS's powerful template tag system provides a flexible way to meet this requirement, allowing you to easily filter and display a list of content from specific authors.This article will introduce you to how to display a list of articles published by a specific author in AnQiCMS, helping you better organize your website content.##

2025-11-08

How to display the links and titles of the previous and next articles on the article detail page?

When a reader visits an article of interest, they often hope to browse related or continuous content seamlessly, rather than returning to the list page to search again.Provide navigation links to "Previous" and "Next" articles on the article detail page of the website, which is an effective way to enhance this reading experience and increase user stickiness.It can not only guide users to explore the website content in depth, but also optimize the internal link structure of the website to a certain extent, making it friendly to search engines.AnQiCMS (AnQiCMS) is a powerful content management system that fully considers the needs of content operation

2025-11-08

How does AnQiCMS implement intelligent recommendation and display of related articles?

In content operation, effectively recommending relevant articles to readers can not only significantly increase user stay time and page views, but also indirectly promote search engines to crawl and allocate weights to the website's content through internal link optimization.AnQi CMS is well-versed in this, providing a smart and flexible mechanism to help users easily implement the recommendation and display of related articles.How does AnQiCMS implement intelligent article recommendation?

2025-11-08

How to display the publish time and update time of articles in AnQiCMS templates?

Understand the publication and update time of an article, which not only helps readers judge the timeliness of the content and avoid outdated information, but also is an important consideration for search engine optimization (SEO).AnQiCMS as an efficient content management system provides flexible template functions, allowing you to easily display these key time information on your website.

2025-11-08

How to customize the URL static rules of the article detail page in AnQiCMS?

In website operation, a clear and friendly URL structure is crucial for search engine optimization (SEO) and user experience.AnQiCMS provides flexible URL rewriting (URL rewrite) functionality, allowing users to customize the URL format of article detail pages according to their needs.This article will introduce in detail how to customize the URL static rules for the article detail page in AnQiCMS.Why do you need to customize URL static rules?

2025-11-08