What are some practical scenarios for using the `if/else` logical judgment tags in AnQi CMS to control content display conditions?

Calendar 👁️ 64

In the template design of AnQi CMS,if/elseLogical judgment tags are extremely powerful tools that give vitality to the dynamic display of website content.By flexibly using this tag, we can intelligently control the display and hiding of elements on the page based on different conditions, thereby providing users with more accurate and personalized browsing experiences, and also greatly enhancing the operational efficiency of the website.

Imagine if your website needs to display different content for different scenarios, or if certain information is only visible when certain conditions are met, at this timeif/elseThe label comes in handy. It allows you to make conditional judgments directly in the front-end template, avoiding the cumbersome modification of back-end logic, making content operation and template maintenance more convenient.

Next, let's take a look togetherif/elseWhat are some very practical scenarios for logical judgment tags in controlling the display conditions of content.

Dynamic content display: delivering information accurately.

Many times, the content on a website needs to be presented according to its own attributes.if/elseTags can help us achieve this, making the content display more intelligent.

For example, when you publish an article with a thumbnail or a product with a cover image, we usually want to display these images on the list page or detail page.But what if some content does not have an uploaded image? Displaying a blank or broken image icon directly would severely affect user experience.At this point, you can add a simple judgment in the template:

{% if item.Thumb %}
    <img src="{{item.Thumb}}" alt="{{item.Title}}">
{% else %}
    <img src="/static/images/default-thumb.png" alt="默认图片">
{% endif %}

This code means, if the current content has a thumbnail, display it.If not, display a preset default image. This not only ensures the beauty of the page but also enhances the integrity of the content.

For example, AnQi CMS supports setting "recommended attributes" for content, such as "headline", "recommended", "slideshow", and so on.We may wish to display different articles in different areas of the homepage based on these properties.You can pass throughif/elseTo determine whether the content has a specific attribute to decide its position or style on the page:

{% if archive.Flag contains 'h' %}
    <span class="badge headline">头条</span>
{% elif archive.Flag contains 'c' %}
    <span class="badge recommended">推荐</span>
{% endif %}

This article, marked with the 'headline' attribute, can be specially highlighted to attract more attention.

For content that needs to differentiate between members and regular users, the Anqi CMS built-in user group management and VIP system provides the foundation.You can control the visibility based on the user's level or the reading permissions of the content.For example, determine whether an article is exclusive VIP content and display different prompts or content accordingly:

{% if archive.ReadLevel > 0 %}
    <p>此内容为VIP专属,请升级会员查看完整内容。</p>
    {# 或者,如果用户是VIP,直接显示内容 #}
    {% if user.IsVip %}
        <div>{{archive.Content|safe}}</div>
    {% else %}
        <p>此内容为VIP专属,请 <a href="/vip-upgrade">升级会员</a> 查看完整内容。</p>
    {% endif %}
{% else %}
    <div>{{archive.Content|safe}}</div>
{% endif %}

This refined control helps you achieve content monetization and the operation of a membership system.

Optimize page layout and navigation: enhance user-friendliness

A great website should not only be rich in content, but also have simple and efficient layout and navigation.if/elseTags are also indispensable when building flexible page structures.

Highlighting the current page or category being visited by the user in website navigation is a common practice to enhance user experience. Anqi CMS navigation tags will provide aIsCurrentproperty, combinedif/elseYou can easily achieve this effect:

{% navList navs %}
    {% for item in navs %}
        <li class="{% if item.IsCurrent %}active{% endif %}">
            <a href="{{ item.Link }}">{{item.Title}}</a>
        </li>
    {% endfor %}
{% endnavList %}

Users can clearly know where they are on the website.

For websites with multi-level categories, drop-down menus or sub-navigation are only displayed when there are subcategories, making the interface cleaner. By determining the categories'HasChildrenAttribute, you can intelligently control the display of sub-navigation:

{% categoryList categories with moduleId="1" parentId="0" %}
    {% for item in categories %}
        <li>
            <a href="{{ item.Link }}">{{item.Title}}</a>
            {% if item.HasChildren %}
                <ul class="sub-menu">
                    {# 这里可以再次循环显示子分类 #}
                </ul>
            {% endif %}
        </li>
    {% endfor %}
{% endcategoryList %}

On the article detail page, there are usually 'Previous' and 'Next' navigation links.If the current article is the first or last in the series, the corresponding navigation link should not appear.prevArchiveandnextArchiveLabel combinationif/elseIt ensures that links are only displayed when there is a previous or next article:

{% prevArchive prev %}
    {% if prev %}
        <a href="{{prev.Link}}">上一篇:{{prev.Title}}</a>
    {% else %}
        <span>没有上一篇了</span>
    {% endif %}
{% endprevArchive %}

{% nextArchive next %}
    {% if next %}
        <a href="{{next.Link}}">下一篇:{{next.Title}}</a>
    {% else %}
        <span>没有下一篇了</span>
    {% endif %}
{% endnextArchive %}

Enhance user experience and interaction: more considerate website services

if/elseLogical judgment can play a key role in processing user-generated content (UGC), such as distinguishing the review status of comments and messages.

The AnQi CMS comment and message function supports review mechanism.In the template, we can display different information to the user based on the content status.For example, if a comment is still under review, you can give a "under review" prompt instead of displaying the content directly:

”`twig {% commentList comments with archiveId=archive.Id type=“list” %}

{% for item in comments %}
    <div>
        {% if item.Status != 1 %}

Related articles

How to use the `pagination` tag to generate a page navigation that conforms to user habits for articles or product lists?

In website operation, how to allow users to easily browse a large amount of content and find the information they are interested in is a crucial topic.Especially on pages such as article lists and product displays, reasonable pagination navigation not only improves user experience but is also an indispensable part of search engine optimization (SEO).AnQiCMS (AnQiCMS) understands this point and therefore provides a powerful and flexible `pagination` tag to help us easily generate professional and user-friendly pagination navigation for website content.We will delve deeper into how to utilize Anqi CMS

2025-11-09

How to display the friend link list in the website background configuration of Anqi CMS?

In website operation, friendship links are an important link to enhance website weight, increase traffic, and improve user experience.AnQiCMS (AnQiCMS) provides us with a convenient way to manage and display these links.How can the list of friend links configured on the back-end be displayed on the website front-end?This is actually simpler than imagined, mainly involving two steps: backend configuration and frontend template invocation. ### Step 1: Configure the友情链接 in the background Firstly, we need to add and manage the friendship links in the Anq CMS background management system.According to system design

2025-11-09

How to use the `guestbook` tag to build and display a dynamic guestbook form on the front page?

In AnQiCMS, building a functional message form is an important way to interact effectively with users, collect feedback, or obtain potential customer information.It is pleasing that with its powerful template tag system, especially the `guestbook` tag, we can easily create and display a dynamic and flexible guestbook form on the front page without writing complex backend code.The core of flexibly building a message form

2025-11-09

How to retrieve and display all the detailed content of a single page, including the slide group image, using the `pageDetail` tag?

In Anqi CMS, a single page is an indispensable part of the website structure, commonly used to display 'About Us', 'Contact Information', 'Service Introduction', etc., which are relatively fixed and do not require frequent updates.For these pages, we usually want to be able to flexibly control the way content is displayed, including text, images, and even slide group images.The `pageDetail` tag is born for this, it allows us to easily retrieve and display all the detailed content of a single page.###

2025-11-09

How to implement diverse data layout and display with the `for` loop tag in AnQi CMS?

How to present information in a more rich and attractive way during website content operation is the key to improving user experience and site activity level.AnQiCMS (AnQiCMS) provides us with the tool to achieve this goal with its flexible content model and powerful template engine.Among them, the `for` loop iteration tag is the essential core tool for us to perform diverse formatting and display.Imagine your website is not just a static pile of articles, but can intelligently present lists of articles, product galleries, category navigation, user comments, and even custom parameters based on different scenarios

2025-11-09

How to format a timestamp into a readable date and time using the `stampToDate` tag in AnQi CMS?

In website operation, the display of time information is crucial. Whether it is the publication date of articles, the update time of products, or the submission time of comments, a clear and easy-to-read date and time format can greatly enhance the user experience.The original timestamp is machine-friendly, but it is cryptic to ordinary visitors.Fortunately, AnQiCMS (AnQiCMS) provides a very convenient template tag——`stampToDate`, which can easily format timestamps into the date and time we are familiar with.### `stampToDate` label

2025-11-09

How to use the `system` tag to retrieve and display the global information of a website, such as the website name, Logo, and filing number?

It is crucial to maintain the consistency of brand image and the accuracy of information in website operation.AnQi CMS is an efficient content management system that provides us with a convenient way to manage and display these core information.Today, let's delve into how to use the `system` tag of Anqi CMS to easily obtain and display global information on the website template, such as the website name, Logo, and filing number.

2025-11-09

How to display the contact information set in the website backend on the front page of AnQi CMS?

When using Anq CMS to build a website, displaying the contact information set in the background to the website front end is a key step to enhance user experience and establish trust.AnQi CMS provides a very intuitive and flexible way, even without a strong technical background, it can be easily realized. ### Configure the contact information of the website backend Firstly, you need to configure the contact information in the Anqi CMS backend management interface. Generally, you can find the 'Background Settings' in the left navigation bar, clicking on it will show the 'Contact Information Settings' option.

2025-11-09