How to retrieve and display details of a specific user group (such as VIP level) in AnQiCMS template?

Calendar 👁️ 70

In AnQiCMS, when managing users and content, we often encounter the need to display different information based on the user's identity (such as VIP level).The powerful template engine and user group management features of AnQiCMS make it very intuitive and efficient to achieve this goal.

Today, let's discuss how to retrieve and flexibly display detailed information of specific user groups in the AnQiCMS template, such as the name of the VIP level.

Learn about the user group and VIP system of AnQiCMS

An QiCMS is built with a comprehensive user group management and VIP system, which allows us to divide users into different permission levels and even support paid content.In the background, you can define multiple user groups, such as " ordinary usersThis information can be easily displayed on the front-end page through template tags.

In order to display the user group details in the template, our core approach is to take two steps: first, obtain the current user's ID and the user group ID associated with it; second, based on this user group ID, further obtain the detailed information of the user group (such as the VIP level name).

The first step: Get the current user ID and the user group ID it belongs to

In the AnQiCMS template, we can useuserDetailLabel to retrieve the details of the current user (or specified user).This tag requires a user ID as a parameter.In most cases, you will operate on the user's personal center page or any page that needs to display user information.currentUserId.

userDetailTags provide many user-related fields, includingGroupIdThe field is the key to obtaining the user group details next.

Here is a simple example showing how to obtain the current user's ID and further extract itsGroupId:

{# 假设 currentUserId 变量已由后端控制器传递至模板 #}
{% userDetail currentUserDetail with id=currentUserId %}
{% if currentUserDetail %}
    {# 成功获取到用户详情,现在提取用户组ID #}
    {% set userGroupId = currentUserDetail.GroupId %}
    
    {# 可以在此处打印一些调试信息,以便确认是否正确获取 #}
    {# <p>用户名:{{ currentUserDetail.UserName }}</p> #}
    {# <p>用户组ID:{{ userGroupId }}</p> #}
{% else %}
    {# 用户未登录或未找到该用户ID的处理 #}
    {# <p>用户未登录或用户ID无效。</p> #}
{% endif %}

In the code above, we first try to go throughuserDetailtag to obtaincurrentUserIdthe corresponding user details, and assign it tocurrentUserDetailthe variable. If it is successfully retrieved, we takecurrentUserDetailoutGroupIdand store it inuserGroupIdIn the variable, preparing for the next step.

Second step: Get user group details based on user group ID

Once we have the user'sGroupId, we can useuserGroupDetailLabel to get detailed information about the user group. This label also acceptsid(User Group ID) orlevel(User Group Level) as a parameter. Since we have already obtainedGroupIddirectlyidParameters are the most convenient way.

userGroupDetailThe fields provided by the label include.Title(Group name, usually the VIP level name),Description(Group introduction),Level(Group level value) and so on.

Following the above example, let's get the detailed information of the user group:

{% if userGroupId %} {# 确保 userGroupId 存在 #}
    {% userGroupDetail userGroup with id=userGroupId %}
    {% if userGroup %}
        {# 成功获取到用户组详情,现在可以展示信息了 #}
        {# <p>用户组名称:{{ userGroup.Title }}</p> #}
        {# <p>用户组等级:{{ userGroup.Level }}</p> #}
        {# <p>用户组描述:{{ userGroup.Description }}</p> #}
    {% else %}
        {# 未找到对应的用户组(可能已删除或ID无效) #}
        {# <p>未找到对应的用户组信息。</p> #}
    {% endif %}
{% endif %}

Here, we useuserGroupIdto query the details of the user group and store the results inuserGroupthe variable. Then, we can accessuserGroup.TitleTo get the name of the VIP level,userGroup.LevelOr get the level value,userGroup.DescriptionTo display more information.

Integration and practical application

Combine the above two steps, and we can fully display the user's VIP level in the template.We can also add some simple logical judgments, according to the user group level to assign different styles or display different prompt information.

{% set currentUserId = 1 %} {# 示例:假设当前用户ID为1,请替换为实际从后端获取的变量 #}

<div class="user-info-panel">
    {% userDetail currentUserDetail with id=currentUserId %}
    {% if currentUserDetail %}
        {% set userGroupId = currentUserDetail.GroupId %}
        
        <p>欢迎回来,<strong>{{ currentUserDetail.UserName }}</strong>!</p>
        
        {% userGroupDetail userGroup with id=userGroupId %}
        {% if userGroup %}
            <span class="user-level vip-level-{{ userGroup.Level }}">
                您当前的身份是:<strong class="vip-text-{{ userGroup.Level }}">{{ userGroup.Title }}</strong>
                {% if userGroup.Description %}<small>({{ userGroup.Description }})</small>{% endif %}
            </span>
        {% else %}
            <span class="user-level">您当前的身份是:普通用户(用户组信息缺失)</span>
        {% endif %}

        {# 还可以根据VIP等级显示不同的内容或功能入口 #}
        {% if userGroup.Level >= 2 %} {# 假设Level 2及以上是VIP #}
            <p>作为尊贵的{{ userGroup.Title }},您可以访问专属内容和特权!</p>
            <a href="/vip-exclusive-content">前往VIP专属页面</a>
        {% else %}
            <p>升级成为VIP,解锁更多精彩!</p>
            <a href="/upgrade-vip">立即升级</a>
        {% endif %}

    {% else %}
        <p>您好!请<a href="/login">登录</a>或<a href="/register">注册</a>,享受更多服务。</p>
    {% endif %}
</div>

In this comprehensive example, we not only obtain and display the user's VIP level name and description, but also judge different display copy and functional links according to the level. Throughvip-level-{{ userGroup.Level }}Such CSS class names, you can also provide unique visual styles for VIP users of different levels.

Points to note

  • Obtaining the user ID: As shown in the above example,currentUserIdEnsure that you can pass the information from the backend controller correctly to the template in practical applications. In the AnQiCMS page context, it usually contains information about the currently logged-in user.
  • Back-end configurationAll user groups (including VIP levels) must be configured in advance in the "User Group Management and VIP System" of the AnQiCMS backend to ensure correct template calls. * **

Related articles

How to display the visitor message form and manage the message results in AnQiCMS?

Maintaining interaction with website visitors, collecting user feedback is a very important link that each website operator attaches great importance to.Whether it is to answer doubts, collect suggestions, or provide customer service, an efficient and convenient comment system can greatly enhance user experience and operational efficiency.AnQiCMS fully understands this and provides us with a simple and efficient visitor message function, making the entire process from form display to result management easy and effortless. ### Easily Build Visitor Message Form AnQiCMS uses flexible template tags to display visitor message forms on the website frontend.

2025-11-08

How to implement content list filtering by custom parameters in AnQiCMS?

In AnQi CMS, flexibly displaying and filtering content is one of the core needs for website operation.As the content structure of a website becomes increasingly complex, for example, if you operate an e-commerce platform that needs to filter products by color and size, or a real estate website that needs to filter housing resources by type and area, traditional classification tags may be insufficient.This is using the powerful custom parameter function of Anqi CMS, which can easily realize the filtering and display of content lists according to the parameters you define, greatly enhancing user experience and the organization efficiency of website content.

2025-11-08

How to display category thumbnails or Banner group images in AnQiCMS?

The visual presentation of website content is the key to attracting users and enhancing experience.Especially on the category page, a beautiful thumbnail or a set of eye-catching banner images can make the content clear to the user and stimulate browsing interest.AnQiCMS as a powerful content management system, provides a flexible image management and calling mechanism, allowing you to easily set and display unique visual elements for website categories.### One, Background Configuration: Add Visual Attraction to Your Categories Firstly, you need to make the corresponding configuration in the background to display images for categories in AnQiCMS

2025-11-08

How to set the website to "closed" status and display a custom prompt message in AnQiCMS?

During the operation of the website, it is sometimes necessary to temporarily close the website, whether it is for system upgrades, data maintenance, or a brief adjustment of content, AnQiCMS provides a simple and efficient shutdown feature to help us elegantly manage the temporary shutdown status of the website.This not only avoids the user from seeing an error page and affecting the experience, but also clearly conveys information and maintains the brand image. We will learn in detail how to set the website to "closed" status in AnQiCMS and display personalized prompt information.

2025-11-08

How does AnQiCMS filter or replace external links in content to standardize display?

External links contained in website content, if not managed properly, may have a negative impact on the website's search engine optimization (SEO) effect, user experience, and even the quality of the content.AnQiCMS as a comprehensive content management system, provides a series of powerful and flexible tools to help you effectively filter or replace external links in the content, ensuring the standardized display of website content.

2025-11-08

How to generate random text of a specified length as placeholder content in AnQiCMS template?

## Generate random text of a specified length as placeholder content in AnQiCMS template During website development and content operation, we often encounter scenarios where we need to fill in placeholder content (Placeholder Content).Whether it is designing a new template, testing page layout, or giving an initial preview when the content is not fully ready, placeholder text can help us quickly build prototypes, intuitively evaluate the visual effects, and do not need to wait for the real content to be filled in.

2025-11-08

How to debug template in AnQiCMS and view the structure and value of variables (using dump filter)?

When developing website templates, we often encounter such confusion: what data does a variable in the template contain?What is its structure? What is the type? And what is the specific value?If these questions cannot be answered quickly, the debugging process will become extremely繁琐and time-consuming.Fortunately, AnQiCMS has provided us with a powerful and convenient debugging tool——`dump` filter, which can help us easily reveal the true face of variables.AnQiCMS developed in Go language, using a template engine syntax similar to Django

2025-11-08

How to safely extract strings or HTML content and add an ellipsis in AnQiCMS templates?

When operating a website, we often need to display article summaries, product descriptions, or user comments and the like.This text, if not processed, is displayed directly and completely. Long text may disrupt the page layout, affecting the overall aesthetics and information transmission efficiency.This is particularly important to truncate the content appropriately and add an ellipsis.AnQiCMS as an efficient and customizable content management system, its powerful template engine developed based on the Go language provides us with a simple and intelligent solution.Pass through built-in filters (filters)

2025-11-08