As an experienced website operations expert, I am well aware that the flexibility of content display is crucial for user experience and operational efficiency in my daily work.AnQiCMS (AnQi Content Management System) is chosen by many enterprises and operators largely due to its powerful customizability and simple and efficient template engine.flagWhether the attribute (such as "recommended" or "headline") is set and adjust the content display accordingly.

Use AnQiCMS's 'Flag' attribute to make the content more expressive

In the AnQiCMS backend, when we edit documents, we will see an option for "recommended properties". Here, such as头条[h]/推荐[c]/幻灯[f]/特荐[a]Multiple identifiers.These "Flag" properties are powerful tools provided by AnQiCMS for content operators, allowing them to classify and tag documents in a fine-grained manner, and then dynamically change the style, layout, or even display additional functional modules in the front-end template.For example, an article marked as "top news" may want to have a more prominent title color or a special corner mark on the homepage list; while a product marked as "recommended" may need to be placed in the "hot recommendations" area of the sidebar.

Understanding the principle of these Flag attributes is the first step. According to the AnQiCMS documentation, these attributes are marked by corresponding letters, such ashrepresenting the headline,cRepresents a recommendation. When a document has multiple Flags set, itsFlagThe value will be a string containing all these letters (for example, if it is both headline and recommendation, thenFlagthe value may be "hc").

Get the document's properties in the templateFlagProperty value

To judge the Flag attribute of the document in the template, we first need to correctly obtain the value of this attribute. AnQiCMS provides two main scenarios to obtain the document'sFlagattribute:

  1. In the document detail page:When you are on the detail page of a document, you can usually directly go througharchiveVariables (or usearchiveDetailTag) to access various properties of the current document. At this point, obtaining the Flag attribute is very direct, just by using{{ archive.Flag }}.

    <p>当前文档的 Flag 属性值:{{ archive.Flag }}</p>
    
  2. In the document list loop:When you usearchiveListWhen looping through multiple documents, if you want to access the properties of each document within the loop,Flagyou need to pay special attention to one parameter of thearchiveListtag:showFlag="true"only when this parameter is set totruewhen, each document'sitem.Flagproperty will be loaded and accessible in the loop. For example:

    {% archiveList articles with type="list" limit="10" showFlag=true %}
        {% for item in articles %}
            <li>{{ item.Title }} - Flag: {{ item.Flag }}</li>
        {% endfor %}
    {% endarchiveList %}
    

    here,itemrepresents each document in the loop,item.Flagwill return the Flag attribute string of the document.

Precise judgment: usecontainFilter

obtaining toFlagAfter the attribute value, the key is how to determine whether the string contains the specific Flag letter we want. The AnQiCMS template engine has built-in powerful filter mechanisms, whichcontainThe filter is exactly the tool to solve this problem.

containA filter used to determine if a string (or array) contains a specific keyword (substring). It returns a boolean value (trueorfalse) which makes it very suitable for use withifLogical judgment tags are used together.

Here are some specific usage examples:

1. Determine if the document is set as "Top News":

Suppose you want to check the current document (or the document in the list ofitem) Does it have the 'Top News' (h) attribute. You can write it like this:

{% if archive.Flag|contain:"h" %}
    <span class="badge headline-icon">头条</span>
{% else %}
    <span class="badge normal-item">普通文章</span>
{% endif %}

Or in a list loop:

{% archiveList articles with type="list" limit="10" showFlag=true %}
    {% for item in articles %}
        <li {% if item.Flag|contain:"h" %}class="highlight-headline"{% endif %}>
            <a href="{{ item.Link }}">{{ item.Title }}</a>
            {% if item.Flag|contain:"h" %}
                <i class="icon-headline"></i>
            {% endif %}
        </li>
    {% endfor %}
{% endarchiveList %}

2. Determine if the document is set to 'Recommended' or 'Slideshow':

If you want to determine whether the document is a "recommended" (c) or a "slide" (f) among any of them, you can use the logicaloroperator:

{% if archive.Flag|contain:"c" or archive.Flag|contain:"f" %}
    <span class="badge featured-slideshow">推荐/幻灯内容</span>
{% endif %}

3. Store the judgment result in a variable for better readability (use)setTag):

When your judgment logic is complex or you need to use the same judgment result multiple times, you can store it in a variablecontainAssign the result of the filter to a new variable, which makes the template code clearer:

{% set isRecommended = archive.Flag|contain:"c" %}
{% set isHeadline = archive.Flag|contain:"h" %}

{% if isRecommended and not isHeadline %}
    <p>这是一篇推荐但非头条的文章。</p>
{% elif isHeadline %}
    <p>这是一篇醒目的头条文章!</p>
{% endif %}

This method is particularly useful when the template code is long, as it helps you better manage and understand the business logic.

Application scenarios and **practice

Mastering the method of judging the Flag attribute, you can achieve various dynamic content display effects in the AnQiCMS template:

  • Distinguishable display of icons or text:Show labels such as 'Hot', 'Recommended', 'Original', etc. next to the article title based on the Flag.
  • Adjust the layout and style:With