How does AnQiCMS display user details and user group information in user group management?

In AnQiCMS, effectively managing users and user groups is a key factor in building personalized websites, implementing member strategies, and achieving content monetization.By flexibly using its built-in template tags, we can easily display users' detailed information and their user group affiliations on the website front end, providing users with a more customized and interactive experience.

The “User Group Management and VIP System” feature provided by AnQiCMS enables website operators to divide different user groups based on business needs and define exclusive permission levels for these groups.Whether providing paid content, building a membership service, or simply distinguishing between ordinary users and privileged users, user groups play a core role.And presenting these background settings logic information in a friendly manner to the user is an important means to enhance user experience and guide users to upgrade their membership.

Flexible display of user details:userDetailThe magic use of tags

When we want to display specific user personal information on the website front-end, AnQiCMS providesuserDetailLabel.This tag can help us get rich data such as username, real name, avatar, email, phone number, as well as VIP expiration time, account balance and invitation code.

to useuserDetailtags, we usually specify a user's ID, for example:

{# 假设我们想展示ID为1的用户信息 #}
{% userDetail targetUser with id="1" %}
<div class="user-profile">
    <h2>{{ targetUser.UserName }}的个人主页</h2>
    {% if targetUser.AvatarURL %}
        <img src="{{ targetUser.AvatarURL }}" alt="{{ targetUser.UserName }}的头像" class="user-avatar">
    {% endif %}
    <p>真实姓名:{{ targetUser.RealName }}</p>
    <p>用户邮箱:{{ targetUser.Email }}</p>
    <p>手机号码:{{ targetUser.Phone }}</p>
    <p>账户余额:{{ targetUser.Balance }}</p>
    {# 对于时间戳字段,我们可以使用 AnQiCMS 的 stampToDate 标签进行格式化 #}
    {% if targetUser.ExpireTime %}
        <p>VIP过期时间:{{ stampToDate(targetUser.ExpireTime, "2006年01月02日 15:04") }}</p>
    {% endif %}
</div>
{% enduserDetail %}

In this code,targetUserIt is the variable name defined for the user detail data we obtain. Through it, we can easily call various user information as if accessing object properties. Especially likeExpireTimeSuch a timestamp field, we can utilizestampToDateLabel, format it into a readable date and time, rather than a string of hard-to-understand numbers.

Reveal user grouping information:userGroupDetailThe powerful tag

Just displaying a user's personal information may not be enough. Often, we also need to inform the user of which user group they belong to, as well as the privileges or introductions of that user group. At this time,userGroupDetailThe label comes into play. It can retrieve detailed data such as the name, description, level, and purchase price of the user group based on the user group's ID or level.

For example, if we want to display the details of the user group with ID 1:

{# 假设我们想展示ID为1的用户组详情 #}
{% userGroupDetail vipGroup with id="1" %}
<div class="user-group-info">
    <h3>用户组名称:{{ vipGroup.Title }}</h3>
    <p>用户组等级:{{ vipGroup.Level }}</p>
    <p>用户组介绍:{{ vipGroup.Description }}</p>
    <p>原价:{{ vipGroup.Price }}</p>
    <p>优惠价:{{ vipGroup.FavorablePrice }}</p>
    {# 如果后台为用户组设置了自定义配置,可以通过 Setting 字段获取 #}
    {% if vipGroup.Setting.specialBenefit %}
        <p>专属福利:{{ vipGroup.Setting.specialBenefit }}</p>
    {% endif %}
</div>
{% enduserGroupDetail %}

Here,vipGroupThis is a variable used to store user group details. Through it, we can clearly display the group name, level, price, and any custom settings made in the background (such asspecialBenefit).

Combine user and group information ingeniously: Build a personalized user center

The true charm of AnQiCMS lies in its high flexibility, we canuserDetailanduserGroupDetailThese tags combined help to build a rich, dynamic personal center or member status page for users.

Imagine, after the user logs in, we want to display a message like 'Welcome [username], you are a [group name] user' on their personal dashboard, and show their exclusive benefits. This can be achieved in the following way:

`twig {# Assume the user is already logged in, we can directly obtain the current user details. If you need to specify a user, you can add the id parameter #} {% userDetail currentUser %}

<h2>欢迎您,{{ currentUser.UserName }}!</h2>
<p>您的用户ID:{{ currentUser.Id }}</p>
<p>您的手机号码:{{ currentUser.Phone }}</p>
<p>您的邀请码:{{ currentUser.InviteCode }}</p>

{# 通过当前用户的 GroupId 字段,获取其所属用户组的详细信息 #}
{% userGroupDetail currentGroup with id=currentUser.GroupId %}
<