How to display a user or user group in the template

In the template design of AnQi CMS, it is crucial to be able to flexibly display user or user group information, which is essential for building personalized and interactive website experiences.The Auto CMS provides intuitive and powerful template tags, allowing you to easily display rich information such as users' profiles and their user groups on the website front end, thereby enhancing user engagement and the professionalism of the website.

Whether you want to display the user's nickname and membership level in the article comment section, or show specific content and features based on the user's identity or group membership, the Anqi CMS provideduserDetailanduserGroupDetailLabels can be your helpful assistant.

1. Get user details:userDetailtags

userDetailThe label is used to obtain detailed information of a single user. It allows us to accurately extract various data of the user based on the user ID or the current context (such as the currently logged-in user).

Basic Usage

In general, if you want to display information about the currently logged-in user, you usually do not need to explicitly specify the user ID. The system will automatically identify the logged-in user context. If you need to retrieve information about a specific user, such as through the ID of the commenter, you will need toidParameters can be used to specify the user ID.

Its basic structure is as follows:{% userDetail 变量名 with name="字段名称" id="用户ID" %}

The fields that can be obtained by the user

userDetailTags provide very rich fields, covering the core information of users, and you can according tonameThe parameter is used to specify the specific content to be retrieved:

  • User ID (Id): The unique identifier for the user.
  • Username (UserName): Usually the user's login name or nickname.
  • Real Name (RealName): The real name of the user (if filled in).
  • User avatar (AvatarURL,FullAvatarURL): User-set avatar address.FullAvatarURLMay provide the full path.
  • User email (Email): User's registration email.
  • User phone number (Phone): Users phone number.
  • User group ID (GroupId): 用户所属用户组的唯一ID。
  • Is the user a distributor (IsRetailer): 一个布尔值,指示用户是否具有分销员身份。
  • Account balance (Balance): 用户账户中可用的资金。
  • Cumulative income (TotalReward): User's cumulative earnings obtained through the platform.
  • Invitation Code (InviteCode): User's exclusive invitation code.
  • Last Login Time (LastLogin): Timestamp of the user's last login, which needs to bestampToDateformatted using a filter for display.
  • VIP过期时间 (English)ExpireTime): 用户VIP身份的过期时间戳,同样需要格式化。
  • User link (Link): 指向用户个人主页或其他相关页面的链接。

Example: Display the login user's information at the top of the page

Suppose we want to display the current login user's avatar, nickname, and expiration information based on their VIP status in a certain area of the website.

English

<div>
    {# 获取并显示用户昵称 #}
    {% userDetail userName with name="UserName" %}
    <p>欢迎您,{{ userName }}!</p>

    {# 获取并显示用户头像,如果未设置则显示默认头像 #}
    {% userDetail userAvatar with name="AvatarURL" %}
    {% if userAvatar %}
        <img src="{{ userAvatar }}" alt="{{ userName }}的头像" style="width: 50px; height: 50px; border-radius: 50%;">
    {% else %}
        <img src="/static/images/default-avatar.png" alt="默认头像" style="width: 50px; height: 50px; border-radius: 50%;">
    {% endif %}

    {# 获取用户组ID,以便进一步获取用户组信息 #}
    {% userDetail userGroupId with name="GroupId" %}
    {% if userGroupId %}
        {# 通过用户组ID获取用户组的名称,假设用户组ID为1的用户组是“VIP会员” #}
        {% userGroupDetail userGroupTitle with name="Title" id=userGroupId %}
        <p>您的身份:{{ userGroupTitle }}</p>

        {# 获取