How to display the names and introduction information of different user groups?

Calendar 👁️ 58

Displaying different user group names and introduction information in Anqi CMS is an important part of website personalized operation and content distribution.No matter if you want to display exclusive identifiers for VIP members or provide customized content for users with different permissions, AnQi CMS's flexible template tag system can help you easily achieve this.

Understanding the core approach to user group information

To display the name and introduction of the user group, it is first necessary to clarify two key points: whether the user is logged in, and which user group the user belongs to.The AnQi CMS provides powerful template tags, allowing you to dynamically retrieve and display these data on the front-end page.

The core idea is: first, obtain the user group ID of the current user through user-related tags, and then use the user group detail tags to obtain the corresponding user group name, introduction, and other custom attributes according to this ID or the level of the user group.

Retrieve user group detail template tag

AnQi CMS provides a specialuserGroupDetailThe tag is used to obtain detailed information about user groups. This tag is very flexible and can accurately obtain the required data based on the user group ID or level.

userGroupDetailThe tag supports specifying which user group information to retrieve via the following parameters:

  • idThe unique identifier ID of the user group.
  • level: The level of the user group. Usually, you can choose one as a query condition.

Including the information it can return:

  • Id: The ID of the user group.
  • Title: The name of the user group.
  • Description: The introduction of the user group.
  • Level: The level of the user group.
  • PriceThe purchase price of the user group (if the VIP system is set).
  • FavorablePriceThe discount price of the user group.
  • SettingA key-value pair (map) is used to store any custom attributes you set for the user group in the background.

Understanding this, we can start practicing in the template.

Practice Exercise: Integrate and Display User Group Information

Next, we will demonstrate how to display the names and introductions of user groups in templates through several common scenarios.

Scene one: Display the group name and introduction of the current logged-in user

Assuming you want to display the user group name and its introduction on the personal center or other pages after the user logs in.This requires us to first obtain the user group ID of the currently logged-in user, and then query the details of the user group.

{# 假设当前登录用户的信息已在模板上下文中,并可以通过 {{ user.Id }} 获取到用户ID #}
{% if user.Id %}
    {# 1. 获取当前登录用户的用户组ID #}
    {% userDetail currentUserGroupId with name="GroupId" id=user.Id %}

    {# 2. 根据获取到的用户组ID,查询用户组的详情 #}
    {% userGroupDetail userGroup with id=currentUserGroupId %}
    
    {% if userGroup.Title %}
        <div class="user-group-info">
            <p>您当前的用户组是:<strong>{{ userGroup.Title }}</strong></p>
            {% if userGroup.Description %}
                <p>用户组介绍:{{ userGroup.Description }}</p>
            {% endif %}
        </div>
    {% else %}
        <p>未能获取到用户组信息。</p>
    {% endif %}
{% else %}
    <p>请登录以查看您的用户组信息。</p>
{% endif %}

In this code, we first go throughuserDetailThe tag retrieved the current logged-in userGroupId, and assigned it tocurrentUserGroupIdvariable. Then, we useuserGroupDetailthe tag, passing this incurrentUserGroupIdObtained the complete user group objectuserGroupPassed in the end{{ userGroup.Title }}and{{ userGroup.Description }}Displayed the name and introduction of the user group

Scenario two: Displaying information of a specific user group based on specified ID or level

Sometimes, you may need to display an overview of all user groups on the page or an introduction to a specific VIP level without first obtaining the information of the currently logged-in user. In this case, you can directly go throughidorlevelSpecify the parameter to query the user group.

Query by user group ID:

{# 假设要查询ID为1的用户组(例如:普通会员) #}
{% userGroupDetail normalMemberGroup with id=1 %}
    <div class="member-tier-card">
        <h3>{{ normalMemberGroup.Title }}</h3>
        {% if normalMemberGroup.Description %}
            <p>{{ normalMemberGroup.Description }}</p>
        {% endif %}
        {% if normalMemberGroup.Price %}
            <p>价格:{{ normalMemberGroup.Price }} 元</p>
        {% endif %}
    </div>

{# 假设要查询ID为2的用户组(例如:VIP会员) #}
{% userGroupDetail vipMemberGroup with id=2 %}
    <div class="member-tier-card vip">
        <h3>{{ vipMemberGroup.Title }}</h3>
        {% if vipMemberGroup.Description %}
            <p>{{ vipMemberGroup.Description }}</p>
        {% endif %}
        {% if vipMemberGroup.FavorablePrice %}
            <p>优惠价:{{ vipMemberGroup.FavorablePrice }} 元</p>
        {% endif %}
    </div>

Query by user group level:

{# 假设要查询等级为1的用户组 #}
{% userGroupDetail levelOneGroup with level=1 %}
    <p>等级为1的用户组名称:{{ levelOneGroup.Title }}</p>

{# 假设要查询等级为5的最高级用户组 #}
{% userGroupDetail highestLevelGroup with level=5 %}
    <p>最高等级({{ highestLevelGroup.Level }})用户组:{{ highestLevelGroup.Title }}</p>

These examples demonstrate how to directly locate and extract information for specific user groups, allowing you to flexibly display this content in different areas of the website.

Further: Using Custom User Group Settings (Setting)

The user group management of AnQi CMS is not limited to the preset fields, you can also add custom attributes for user groups in the background. These custom attributes will be stored inSettingWithin the field, and provided in the form of key-value pairs for template calls. For example, you can set different 'exclusive discounts' or 'customer service hotlines' for different user groups.

Assume you have set up a custom attribute namedDiscountRate(discount rate) in the background for a certain user group. You can retrieve it in the template like this:

{% userGroupDetail userGroup with id=currentUserGroupId %}
    {% if userGroup.Setting.DiscountRate %}
        <p>您的用户组专属折扣:{{ userGroup.Setting.DiscountRate }}%</p>
    {% endif %}

In this way, you can define an unlimited number of custom information for user groups and flexibly display it on the front end, achieving a highly customized member service.

Summary

The user group management function of AnQi CMS is powerful and flexible, working with intuitive template tags, allowing you to easily display the names, introductions, and custom information of different user groups on the website front-end.From identifying the user's group to obtaining detailed group data, and then utilizing custom settings, the entire process is smooth and efficient, providing solid support for your website content operations and user experience optimization.


Frequently Asked Questions (FAQ)

1. Why do I follow the example code, but I still can't get the group name of the currently logged-in user?Answer: Make sure the user is already logged in on the website. AnQi CMS'suserDetailThe tag needs to depend on whether there is a user ID in the session when retrieving the current logged-in user information. If the user is not logged in, or the login status cannot be correctly passed to the template context (for example, on some non-user center pages), you may not be able to retrieve ituser.IdThus, the subsequent user group information cannot be obtained. Please check your login status and template

Related articles

How to display detailed information of the currently logged-in user (such as username, avatar, VIP status)?

In Anqi CMS, displaying the detailed information of the currently logged-in user, such as username, avatar, and VIP status, is a key step to enhance user experience and build a personalized website.AnQi CMS with its flexible template engine allows us to easily implement these features.This article will introduce how to display this information on your website front-end. ## Retrieve basic information of the currently logged-in user The Anqi CMS template system provides the `userDetail` tag, which is the core tool for retrieving various information of the currently logged-in user.This tag can directly retrieve the user data of the current session

2025-11-08

How to configure and display thumbnails with different processing methods (such as cropping, scaling)?

##驾驭安企CMS缩略图:精细化的配置与灵活的展示,打造视觉冲击力 在网站运营中,图片无疑是吸引用户、提升内容质量的关键元素。While thumbnails, as the first visual touchpoint of website content, their display effect directly affects users' desire to click and the overall beauty of the page.AnQi CMS knows this and provides us with flexible thumbnail configuration and display capabilities, helping us easily manage and present high-quality image content.### Core Configuration

2025-11-08

How to automatically compress images based on size and display them on the front-end?

In website operation, images are an important element to attract visitors and convey information.However, large, unoptimized images often become the 'killer' of website loading speed, not only affecting user experience, but also possibly dragging down search engine rankings.Luckyly, AnQiCMS (AnQiCMS) provides very intelligent and practical image processing functions that can help us easily cope with these challenges, making images clear and fast when displayed on the front end.### Smart compression, goodbye to manual adjustment of large images Have you ever encountered such a situation: in order to maintain image quality

2025-11-08

How to batch generate and display images in Webp format in AnQi CMS?

Website performance is one of the key factors that determine user experience and search engine rankings.Among various optimization methods, image optimization plays a vital role.WebP is a modern image format that boasts excellent compression performance and almost lossless visual quality, and is gradually becoming the new standard for website optimization.How can we efficiently generate and display WebP images in the Anqi CMS management website?AnQi CMS provides very convenient and powerful functional support in this aspect, allowing you to easily achieve the WebPization of website images without delving into technical details

2025-11-08

How to conditionally display different content or styles within a loop?

In website content display, we often encounter the need to display different content or assign unique styles to elements according to the order of data cycles, specific attributes, or states.For example, odd and even rows in the list need different background colors, special markings for certain types of products, or when a field is empty, hide the corresponding area.With its flexible and powerful Django-like template engine, AnQi CMS makes these requirements simple and easy to implement.By cleverly combining loop tags (`{% for ... %}`) and conditional judgment tags (`{% if ... %}`)

2025-11-08

How to define and display temporary variables in the template?

In Anqi CMS template development, mastering how to define and display temporary variables in the template is a very practical skill.It can help us handle data more flexibly, optimize template structures, and write more concise and efficient code.Temporary variables are like the "small tags" you grab on the fly while making a page, used to temporarily store some data for later use.### Why do we need temporary variables? Imagine a scenario: you might need to get a value from a label and then perform a series of operations on it (such as truncating strings, formatting time)

2025-11-08

How to reference and display common code snippets (such as header, footer) in AnQiCMS templates?

It is crucial to maintain consistency in page structure and code maintainability in website construction and content management.For a content management system like AnQiCMS, effectively referencing and managing common code snippets, such as the website header (Header) and footer (Footer), is the key to achieving this goal.Through AnQiCMS's flexible template mechanism, even users with little understanding of technical details can easily implement these features, thus building a website with clear structure and easy maintenance.###

2025-11-08

How to use the template inheritance mechanism to unify and display the website page structure?

When building a website, maintaining consistent page structure, improving development efficiency, and reducing maintenance costs are key to website operations.AnQiCMS (AnQiCMS) leverages its powerful functionality based on the Django template engine syntax to provide us with an efficient template inheritance mechanism, making it easy to unify and flexibly display the structure of web pages. ### The core concept of template inheritance: building the skeleton of a website Imagine that your website is like a house made up of different rooms. Each room (page) has its unique functions and content, but they share the same foundation

2025-11-08