The `moduleDetail` tag returns the `Keywords` field, is it a single keyword or a comma-separated string? How should it be correctly parsed in the template?

Calendar 👁️ 76

In-depth Analysis of AnQiCMSmoduleDetaillabel'sKeywordsField: Format and Template Analysis of Keywords

As an experienced website operations expert, I know that how to efficiently and flexibly handle and display content in a content management system is the key to success.AnQiCMS (AnQiCMS) provides us with great convenience with its simple and efficient architecture.Today, let's delve deeply into a specific issue that often arises in template creation:moduleDetailthe tags returned byKeywordsIs the field a single keyword or a comma-separated string? How should it be correctly parsed and utilized in the template?

To put it directly, frommoduleDetailthe tags returned byKeywordsA field, as well as all fields involving "keywords" in Anqi CMS (such as document keywords, tag keywords, etc.), is acomma-separated string.

This is highly consistent with the design concept of AnQi CMS in the background content management. When entering keywords in the background, the system explicitly requires users to useEnglish comma(,) to separate different keywords. This not only conforms to the common processing method of keyword lists by search engines, but also ensures the uniformity of the data format in internal storage and front-end calls.Therefore, when we pass throughmoduleDetailtags to obtain model-levelKeywordsWhen, you get is a single string containing all the keywords, connected by English commas.

Why is it so important to understand the format of keywords?

Understanding this is crucial for us to correctly utilize these keywords in the template. Directly output the entire string as is to the page.<meta name="keywords" content="...">The label is indeed simple and direct, and it is also one of its basic uses.However, in more rich and interactive front-end presentations, we often need to display each keyword independently.For example, render them as clickable tags (Tag), forming a tag cloud, or as a basis for other content recommendations.If we do not parse this comma-separated string, we will not be able to achieve these more advanced display requirements.

How to correctly parse in the templateKeywords?

The AnqiCMS template engine (which supports Django template engine syntax) provides us with powerful filter functions. Among them,splitThe filter is exactly the tool to handle such needs. It can split a string into an array of strings (slice) based on the specified delimiter, so that we can operate on each keyword individually.

Below, we will demonstrate how to parse through a specific template code examplemoduleDetailthe tags returned byKeywordsand display the fields as a series of clickable tags.

Assuming we are on a model page (such as an article list page or product list page), we need to display the keywords associated with the current model.

{# 首先,使用 moduleDetail 标签获取当前模型的 Keywords 字符串 #}
{% moduleDetail moduleKeywordsString with name="Keywords" %}

<div class="module-keywords-section">
    {% if moduleKeywordsString %}
        <h3>当前模型关键词:</h3>
        <ul class="keywords-list">
            {# 使用split过滤器将逗号分隔的字符串解析成数组 #}
            {% set keywordsArray = moduleKeywordsString|split:"," %}
            
            {% for keyword in keywordsArray %}
                {# 
                   在循环中,每个 keyword 变量都代表一个独立的关键词。
                   我们使用 trim 过滤器移除可能存在的首尾空格,并判断关键词是否为空。
                   为了生成有效的搜索链接,我们还对关键词进行了 urlencode 编码。
                #}
                {% if keyword|trim %}
                <li>
                    <a href="/search?q={{ keyword|trim|urlencode }}" class="keyword-tag">
                        {{ keyword|trim }}
                    </a>
                </li>
                {% endif %}
            {% endfor %}
        </ul>
    {% else %}
        <p>该模型暂未设置关键词。</p>
    {% endif %}
</div>

{# 
   在某些特定场景下,您可能需要将已经解析过的关键词数组
   重新合并成一个字符串,例如,为了生成符合特定格式的JSON-LD数据。
   这时,`join`过滤器就派上用场了。
#}
{% if keywordsArray %}
    {% set rejoinedKeywords = keywordsArray|join:", " %}
    <p>重新合并后的关键词(用于其他高级用途):{{ rejoinedKeywords }}</p>
{% endif %}

In this code, we first use{% moduleDetail moduleKeywordsString with name="Keywords" %}We have obtainedKeywordsThe original string of the field. Then, through{% set keywordsArray = moduleKeywordsString|split:"," %}This line, we split this string using a comma as a delimiter into a namedkeywordsArrayarray.

Next, we use{% for keyword in keywordsArray %}Loop through this array. In the loop body, eachkeywordVariables represent an independent keyword. To ensure the neatness of the display and the validity of the links, we usually perform the following processing:

  1. {{ keyword|trim }}: Use.trimThe filter removes any leading and trailing spaces from the keyword string, as the user may accidentally leave spaces when entering in the background.
  2. {% if keyword|trim %}:

Related articles

If I want to restrict certain user groups to only edit specific content models, how can I configure this in the backend, and what is the association with the `moduleDetail` tag?

As an experienced website operations expert, I deeply understand the importance of fine-grained permission management in content operations.An excellent content management system that not only supports a variety of content formats but also provides flexible permission control, ensuring that each team member can work efficiently within their scope of responsibilities while avoiding misoperations and potential security risks.AnQiCMS (AnQiCMS) performs well in this regard, with its powerful user group management and flexible content model mechanism, which is the key to achieving this goal.

2025-11-07

How to get the default category ID of the current content model through the `moduleDetail` tag, so as to build category navigation in the template?

HelloAs an experienced website operation expert, I am more than happy to share with you how to use the `moduleDetail` tag巧妙地 in AnQiCMS templates to obtain the ID of the current content model, and build a dynamic and accurate classification navigation system based on this.The AnQi CMS, with its efficient and flexible content model, provides great convenience for content operators, and a deep understanding of its template tags is the key to unleashing these advantages.

2025-11-07

Why must the `model table name` of the content model be in English lowercase letters? What is the relationship with the underlying Go language development of Anqi CMS?

AnQi CMS, as an enterprise-level content management system meticulously crafted based on the Go language, has always adhered to a rigorous design philosophy on the path of pursuing ultimate performance, stability, reliability, and flexibility.Today, let's delve into a seemingly simple yet deeply technical consideration: why must the table name of the content model be in lowercase English letters?How closely is this related to the underlying development of the Go language?### The foundation of AnQi CMS: Go language and efficient design Firstly

2025-11-07

Does the `moduleDetail` tag provide fields to retrieve the model creation time or update time to achieve more refined template display?

As an experienced website operations expert, I fully understand that the precise control and display of time dimension information in content management systems is crucial for website operations and user experience.Whether it is the publication time of the article or the last update time of the content, it can convey important information to the reader and also have a positive impact on search engine optimization (SEO).

2025-11-07

How to dynamically build a link to the home page or list page of the model based on the content model ID in the front-end template?

## The wisdom of dynamically building jump links in the Anqi CMS front-end template based on content model ID As an experienced website operations expert, I know that flexibility and automation are the key to improving efficiency in daily content management.The AnQi CMS provides us with great convenience with its powerful content model customization capabilities and friendly template engine.Today, let's delve into a very practical skill in front-end development: how to dynamically build a link to the home page or list page of the model based on the content model ID without hardcoding the path

2025-11-07

`changelog` mentions that articles and products are generated according to the model, what is the core impact on template creation after upgrading to the old version?

As an experienced website operations expert, I know that the core value of the Content Management System (CMS) lies in its flexibility and scalability.The continuous evolution of AnQiCMS (AnQiCMS) in content management, especially the adjustment of content generation logic in version updates, is a key point worthy of in-depth exploration for us operators and template developers.Today, let's talk about the change mentioned in the `changelog` of Anqi CMS where 'articles and products are generated by models', and what core impacts it brings to the template creation after upgrading to the old version

2025-11-07

Can I define a custom field of image upload type in a content model? How can I display and process these images in the frontend template?

As an experienced website operation expert, I am well aware of the flexibility and powerful features of AnQiCMS in content operation.Especially in this visually-oriented era, the presentation quality and management efficiency of image content directly relate to user experience and the effectiveness of content marketing.Today, let's delve deeply into a common problem that many people encounter: how to define a custom field of image upload type in AnQiCMS content model and elegantly present it on the front-end template.

2025-11-07

How to get the total number of categories under the content model? Does the `moduleDetail` tag support this feature directly?

AnQiCMS (AnQiCMS) is an efficient and flexible content management system, whose powerful content model features make many operators and developers love it.When we operate websites on a daily basis, we often need to make detailed statistics and presentations of the content.For example, under a specific content model, we may want to know how many categories there are in order to display them on the homepage, sidebar, or statistics page.

2025-11-07