The `userDetail` tag supports which parameters to accurately find specific user information?

In AnqiCMS template development, in order to display specific user information on the page, we often use a very practical tag -userDetail. This tag allows us to accurately retrieve and present users' detailed data based on specific conditions.Understanding the parameters it supports is crucial for flexibly building user-related page features.

userDetailThe core function of the label is to obtain data based on clear user identification. When in use, it requires us toidThe parameter is used to specify the user ID to be queried. This is a required parameter and ensures the accuracy of the query.For example, if you want to retrieve user information with ID 1, your tag structure will containid="1".

Once we specify the user ID, we can go throughnameParameters to select the specific user fields to be displayed.nameThe parameter is followed by the user data field name we want to obtain. If you want to store the obtained data in a variable, you canuserDetailAfter the tag, specify a variable name, so that the user field can be called through this variable later; if you just want to output the result directly, you can omit the variable name.

Let's take a detailed look atuserDetailWhat user fields are supported by tags and their respective uses:

  • User ID (Id)This is the unique identifier of the user, usually used for internal logic processing.
    • For example:{% userDetail with name="Id" id="123" %}
  • Parent User ID (ParentId)If your system supports user hierarchy or referral relationships, this field will display the parent user ID of the user.
  • Username (UserName)The username or nickname used to display the user's identity on the page.
    • For example:{% userDetail userProfile with name="UserName" id="456" %}{{ userProfile }}
  • Real name (RealName)The real name of the user, which may be used in scenarios requiring real-name authentication.
  • User introduction (Introduce): The user's personal introduction or self-description.
  • User avatar (AvatarURLandFullAvatarURL): Provide the link to the user's avatar image.AvatarURLIt may be a processed thumbnail or a specific size avatar, andFullAvatarURLIt is usually a link to the original or higher resolution avatar.
    • For example:<img src="{% userDetail with name="AvatarURL" id="789" %}" alt="用户头像">
  • User Email (Email): The user's email address.
  • User phone number (Phone): The user's phone number.
  • User Group ID (GroupId)The user's group ID to which the user belongs, which can be used to judge user permissions or identity.
  • Is the user a distributor (IsRetailer)A boolean value indicating whether the user has distribution qualifications.
  • Account balance (Balance)The account balance of the user.
  • Total earnings (TotalReward)The cumulative total earnings of the user on the platform.
  • Invitation code (InviteCode)The exclusive invitation code for the user, used to recommend new users.
  • Last login time (LastLogin)This field displays the time of the user's last login. This field returns a timestamp, and if you need to display it as a readable date format on the page, you need to use thestampToDatetag for formatting.
    • For example:最近登录:{% userDetail loginTime with name="LastLogin" id="101" %}{{ stampToDate(loginTime, "2006-01-02 15:04") }}
  • VIP expiration time (ExpireTime): If the user is a VIP member, this field will display the expiration time of their VIP service. It is also a timestamp and needs to be usedstampToDateFormat labels.
    • For example:VIP到期:{% userDetail vipExpire with name="ExpireTime" id="101" %}{{ stampToDate(vipExpire, "2006年01月02日") }}
  • User link (Link)If the system generates a separate personal homepage link for each user, this field will provide the link.

Through these parameters and fields,userDetailTags provide very fine user information acquisition capabilities. Whether it is to display user nicknames, avatars, or to query their VIP status or recent activity time, it can be achieved through concise template tags.When designing features that need to display user profiles, member centers, or author information in comment sections, this tag can play an important role.

It should be noted that, due touserDetaillabel'sidThe parameter is mandatory, which means you must obtain the target user's ID in some way before calling the tag. This could be through URL parameters, hidden fields on the page, or in combination with other tags such asarchiveDetailofUserIdGet them. Making good use of these parameters can help us build user-friendly website pages more efficiently and accurately.

Frequently Asked Questions (FAQ)

Q1: If I need to get the information of the currently logged-in user,userDetailCan the tag be directly accessed, or do I need to know itsID?

A1: userDetaillabel'sidThe parameter is required, it needs a clear user ID to search and return information.Therefore, the tag itself cannot directly obtain information about the "current logged-in user" because at the template level, the system does not know who is logged in.Generally, if you need to display the information of the currently logged-in user, you need to pass the ID of the current logged-in user to the template on the backend, or asynchronously load the user ID from Session/LocalStorage on the frontend using JavaScript.

Q2:LastLoginandExpireTimeThe field returns a timestamp, how can I display it on the page in a common datetime format?

A2: LastLoginandExpireTimeThe field indeed returns a Unix timestamp. You can use the built-in function of AnqiCMS.stampToDateLabel to format it. This tag requires two parameters: the timestamp variable and the time format string (Go language time format).For example, to display as “2023/01/01 12:30:00”, you can use it like this:{{ stampToDate(user.LastLogin, "2006年01月02日 15:04:05") }}.

Q3: Can I useuserDetailTag to retrieve information about multiple users at once, or search based on username or other fields?

A3: userDetailThe label is primarily designed to accurately retrieve detailed information about a single user and must be accessed through the user ID (idThe parameter is specified. It does not directly support retrieving multiple users in bulk or searching based on username or other non-ID fields.If your requirement is to display a list of users in bulk, or to filter users based on other conditions, this usually requires combining backend development, through custom list tags or API interfaces to achieve.