In Anqi CMS template design, it is crucial to be able to flexibly display user or user group information, which is essential for building personalized, interactive website experiences.AnQi CMS provides intuitive and powerful template tags, allowing you to easily display users' profiles, user groups, and other rich information on the website front-end, thereby enhancing user engagement and the professionalism of the website.
Whether you want to display users' nicknames and membership levels in the article comment section or hope to show specific content and features based on users' identities or user groups, Anqicms providesuserDetailanduserGroupDetailTags can become your helpful assistant.
1. Get user details:userDetailTag
userDetailThe label is used to obtain detailed information about a single user. It allows us to accurately extract a user's data based on a user ID or 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, it is usually not necessary to explicitly specify the user ID. The system will automatically recognize the context of a logged-in user. If you need to retrieve information about a specific user, such as through the ID of a commenter, you will need to go throughidParameters are used to specify the user ID.
The basic structure is as follows:{% userDetail 变量名 with name="字段名称" id="用户ID" %}
User fields that can be retrieved
userDetailTags provide very rich fields, covering the core information of users, you can use them tonameSpecify the parameter to indicate the specific content to be retrieved:
- User ID (
Id): The unique identifier of the user. - Username (
UserName): Usually the username or nickname. - Real name (
RealName): The real name of the user (if provided). - User avatar (
AvatarURL,FullAvatarURL): The avatar address set by the user,FullAvatarURLMay provide the full path. - User email (
Email): The user's registration email. - User phone number (
Phone)User's phone number. - User group ID (
GroupId): The unique ID of the user's group. - Is the user a distributor (
IsRetailer): A boolean value indicating whether the user has a distributor status. - Account balance (
Balance): The available funds in the user's account. - Total earnings (
TotalReward): The cumulative income earned by the user through the platform. - Invitation code (
InviteCode): The exclusive invitation code of the user. - Last login time (
LastLogin): The timestamp of the last login of the user, which needs to be accessed throughstampToDateThe filter performs formatted display. - VIP expiration time (
ExpireTime): The timestamp of the user's VIP status needs to be formatted as well. - User link (
Link)指向用户个人主页或其他相关页面的链接。
示例:在页面顶部展示登录用户信息
Assuming we want to display the current logged-in user's avatar, nickname, and expiration information based on their VIP status in a certain area of the website.
”`twig {# Check if the user is logged in, usually by checking if the user ID exists #} {% userDetail currentUserId with name=“Id” %} {% if currentUserId %}
<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>
{# 获取