What parameters does the `userDetail` tag support to accurately locate 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 detailed user data based on specific conditions.Understanding the parameters it supports is crucial for flexibly building user-related page features.

userDetailThe core function of the tag is to obtain data based on clear user identification. When in use, it requires us to pass throughidSpecify the parameter to specify the user ID to be queried.This is a required parameter, ensuring the accuracy of the query.id="1".

Once we specify the user ID, we can pass throughnameSelect specific user fields to be displayed by the parameter.nameParameters are followed by the name of the user data field we want to retrieve. If you want to store the retrieved data in a variable,userDetailImmediately follow the tag with a variable name, so that the user field can be accessed through this variable later; if you just want to output the result directly, you can omit the variable name.

Next, let's delve into it in detail.userDetailWhat user fields are supported by the tags, and what their respective purposes are:

  • User ID (Id)This is the user's unique identifier, 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 recommendation relationships, this field will display the parent user ID of the user.
  • Username (UserName)The user's login name 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, may be used in scenarios requiring real-name verification.
  • User Introduction (Introduce)【en】The user's personal introduction or self-description.
  • 【en】User avatar (AvatarURLandFullAvatarURL)【en】: Provides the user's avatar image link.AvatarURL【en】It could be a processed thumbnail or a specific size avatar, andFullAvatarURLThen it is usually a link to the original or higher resolution avatar image.
    • For example:<img src="{% userDetail with name="AvatarURL" id="789" %}" alt="用户头像">
  • User Email (Email): The email address of the user.
  • User phone number (Phone): The phone number of the user.
  • User Group ID (GroupId): The user group ID to which the user belongs, which can be used to determine the user's permissions or identity.
  • Is the user a distributor (IsRetailer)An indicator boolean value, showing whether the user has distribution qualifications.
  • Account balance (Balance)): The account financial balance of the user.
  • Cumulative income (TotalReward)): The cumulative total income of the user on the platform.
  • Invitation Code (InviteCode): Exclusive invitation code for referring new users.
  • Last Login Time (LastLogin)This field returns a timestamp for the last login time of the user. If you need to display it as a readable date format on the page, it needs to be formatted withstampToDatetags.
    • 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. Similarly, it is also a timestamp and needs to be used withstampToDateLabel formatting.
    • 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 that link.

Through these parameters and fields,userDetailTags provide very fine-grained user information acquisition capabilities.Whether it is to display the user's nickname, avatar, or query their VIP status or recent activity time, it can all be achieved through concise template tags.This tag plays an important role when designing features that require displaying user profiles, member centers, or author information in comment sections.

It should be noted that,userDetailTagsidParameters are mandatory, which means you must obtain the target user's ID in some way before calling the tag. This can be done through URL parameters, hidden fields on the page, or by combining other tags (such asarchiveDetailofUserIdto get. Properly utilizing these parameters can help us build user-friendly web pages more efficiently and accurately.

Common Questions (FAQ)

Q1: If I need to retrieve the information of the currently logged-in user,userDetailcan the label be directly retrieved, or do I need to know it first?ID?

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

Q2:LastLoginandExpireTimeHow can I display the timestamp returned by the field in a common date and time format on the page?

A2:LastLoginandExpireTimeField indeed returns Unix timestamp. You can use the built-in of AnqiCMS.stampToDateFormat it with tags.This tag requires two parameters: a timestamp variable and the time format string you want (in Go language time format).{{ stampToDate(user.LastLogin, "2006年01月02日 15:04:05") }}.

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

A3:userDetailTags are mainly designed for precise retrieval of individual user details, and must be accessed through the user ID (idSpecify the parameter) as required.It does not directly support batch retrieval of multiple users 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 with backend development, through custom list tags or API interfaces.