How to display user details and user grouping information in the AnQiCMS user group management?

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

The 'User Group Management and VIP System' feature provided by AnQiCMS allows website operators to divide different user groups according to business needs and define exclusive permission levels for these groups.Whether it is to provide paid content, build membership services, or simply differentiate 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 improve user experience and guide users to upgrade their membership.

Flexible display of user details:userDetailThe clever use of tags

When we want to display specific user information on the website front end, AnQiCMS providesuserDetailThe tag can help us obtain rich data such as username, real name, avatar, email, phone number, and even 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 block,targetUserIt is the variable name defined for the user detail data we obtain. Through it, we can easily access various user information as if accessing object properties. Especially likeExpireTimeSuch a timestamp field, we can utilizestampToDatelabel, format it into a readable date and time instead of a string of difficult-to-understand numbers.

Reveal user grouping information:userGroupDetailThe power of the label

It may not be enough to just display a user's personal information, often we also need to inform the user of which user group they belong to, as well as the privileges or introduction of that group. At this time,userGroupDetailThe tag 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 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, vipGroupIt is used to store group details. Through it, we can clearly display the group name, level, price, and any custom settings in the background (such asspecialBenefit)

Combine users with group information cleverly: Build a personalized user center

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

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

”`twig {# Assume the user is logged in, we can directly retrieve 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 %}
<