How to retrieve and display the user's exclusive `InviteCode` (invitation code) with the `userDetail` tag?

Calendar 👁️ 95

In AnQiCMS, if you want to display users' exclusive invitation codes on the website page, this usually involves the application of membership systems or referral mechanisms. AnQiCMS provides flexible template tags that can help us easily obtain and display various user information, including invitation codes (InviteCode)

To implement this feature, we mainly use AnQiCMS'suserDetailThe label is specifically designed to retrieve detailed data of a specific user from the background database and display it in the front-end template.

UnderstandinguserDetailTag

userDetailThe core function of the tag is to retrieve all available details based on the user's ID. Its basic structure is as follows:

{% userDetail 变量名称 with name="字段名称" id="用户ID" %}

There are several key points to understand:

  • 变量名称This is an optional parameter. If you need to store the data obtained in a temporary variable for subsequent complex processing, you can specify a variable name (for example,currentUser/inviteCodeDataIf not needed, you can simply omit it.
  • name="字段名称"This is used to specify which user information you want to retrieve. For invitation codes, you need to字段名称is set toInviteCode.
  • id="用户ID"This parameter isrequired.It tells AnQiCMS which user's details you want to query. This用户IDcan be a specific number (such asid="123"), can also be a dynamic variable, such as the current logged-in user's ID.

userDetailThe fields that can be obtained by the label are very rich, including not only invitation codes, but also usernames (UserName), real name (RealName)、user avatar(AvatarURL)et al.,InviteCodeThat is the target field we need to obtain this time.

Actual operation: Obtain and display the invitation code

Suppose we want to display a user's own invitation code on a user's personal center page, or on an administrator page to display a specific user's invitation code.

Scenario one: Display the invitation code for the currently logged-in user

In AnQiCMS, when you design pages such as user personal centers, the system usually provides some contextual information for the currently logged-in user. AlthoughuserDetailthe tag documentation explicitly statesidis required but can be omitted on certain default user-related pages (such as the user profile page)idPass the current user ID through parameters or in other ways, it may automatically obtain the information of the currently logged-in user.

The most reliable approach is to ensure that you can obtain the current logged-in user'sID. If your template context already includes the current user's ID (such as incurrent_user.Idsuch a variable in)

{% set userId = 123 %} {# 假设这是当前登录用户的ID,实际应用中会从会话或上下文中获取 #}
<div>
    您的专属邀请码是:
    <strong>{% userDetail with name="InviteCode" id=userId %}</strong>
</div>

if the system supports skipping directly in the user context pageidand defaults to the current user, it can be written more concisely as:

<div>
    您的专属邀请码是:
    <strong>{% userDetail with name="InviteCode" %}</strong>
</div>

Please test which method is more suitable for obtaining the current logged-in user ID based on your actual AnQiCMS version and template context.

Scenario two: Display the invitation code for the specified user (via user ID)

If you know a specific user's ID (for example, when displaying a user list, you need to display each user's invitation code), then you can directly pass in the ID in theidparameters.

For example, to get the user ID of1the invitation code:

<div>
    用户ID为 1 的邀请码是:
    <strong>{% userDetail with name="InviteCode" id="1" %}</strong>
</div>

If you are iterating over a user list and each user object has aIdattribute, you can do this:

{% for user in userList %} {# 假设这里有一个包含用户信息的 userList 循环 #}
    <div class="user-card">
        <h3>{{ user.UserName }} 的邀请信息</h3>
        <p>用户ID:{{ user.Id }}</p>
        <p>专属邀请码:
            <strong>{% userDetail userInviteCode with name="InviteCode" id=user.Id %}</strong>
        </p>
    </div>
{% endfor %}

In this example, we first go throughid=user.IdSpecified the user ID to be queried, then the invitation code obtained is assigned touserInviteCodea variable, and finally displayed on the page.

Advanced usage and注意事项

  1. Assigned to a variable and then processed: In order to maintain the neatness of the template and facilitate subsequent processing, we usually willuserDetailAssign the obtained value to a variable. This way, you can add additional HTML wrapping, styling, or even simple logical judgments to the invitation code.

    {% userDetail userInviteCode with name="InviteCode" id="当前用户ID或指定用户ID" %}
    {% if userInviteCode %} {# 判断邀请码是否存在或不为空 #}
        <p class="invite-code-display">您的邀请码是:<code>{{ userInviteCode }}</code></p>
    {% else %}
        <p class="no-invite-code">暂无专属邀请码。</p>
    {% endif %}
    
  2. Dynamically retrieve the user IDIn practical applications,用户IDIt is usually dynamic. For example, it can be obtained from URL parameters or extracted from the session information of the logged-in user.This logic is usually handled at the controller or routing level, and then the user ID is passed to the template.

  3. Data security and visibility: Invitation codes belong to users' personal information or business sensitive information, and must pay attention to permission control when displayed.Ensure that only the user themselves or administrators with the corresponding permissions can view the invitation code to avoid unnecessary privacy leaks.

By using the above method, you can flexibly obtain and display the exclusive invitation code for users in the AnQiCMS template, providing necessary information display for your website membership system or referral feature.


Frequently Asked Questions (FAQ)

  1. What will the page display if the user does not have an invitation code? Answer:If it passesuserDetailTag to get the `Invite

Related articles

How to display the personal introduction filled in the `Introduce` field on the user's profile page?

In website operation, providing users with personalized profile display, especially the personal introduction filled in by users themselves, can greatly enhance the vitality and sense of belonging of the community.For users of AnQiCMS, it is actually a very intuitive and flexible operation to display the personal introduction filled in by the user in the `Introduce` field on the profile page, mainly relying on the powerful template tag system of AnQiCMS.### Understand the template mechanism of AnQiCMS In AnQiCMS

2025-11-07

How to get the `GroupId` of the user through the `userDetail` tag and further get the detailed information of the user group?

In AnQiCMS, providing personalized content and experience to users is a key link to enhance website stickiness.It is particularly important to understand the details of the user's group to display exclusive content based on user level or provide differentiated service information.Today, let's delve into how to make use of the powerful template tag features of AnQiCMS, through the `userDetail` tag to obtain the `GroupId` of the user, and further use the `userGroupDetail` tag to display the detailed information of these user groups on the website front end

2025-11-07

How to use `AvatarURL` or `FullAvatarURL` to display a user avatar in the template?

In website operation, the user avatar is not just a decoration, it carries the user's identity and is an important part of community interaction and personalized experience.Whether it is in the comment area, author introduction, or member center, a clear user avatar can significantly enhance the website's affinity and professionalism.AnQiCMS as an efficient content management system naturally also provides us with the powerful function of flexibly displaying user avatars in templates.Today, let's talk about how to use the `AvatarURL` and `FullAvatarURL` fields in AnQiCMS templates

2025-11-07

Can the `userDetail` tag retrieve the user's email `Email` and phone number `Phone` and display it on the front end?

In website operation and user experience design, sometimes we need to display specific user information on the front-end page, such as contact email or phone number, in order to provide personalized services or facilitate users to view/update their personal information.It is crucial for users of AnQiCMS to understand how to implement this safely and efficiently.This article will delve into the `userDetail` tag of AnQiCMS, discussing whether it can retrieve and display the user's email (`Email`) and phone number (`Phone`), as well as the matters that need to be paid attention to during use

2025-11-07

How to use the `stampToDate` tag for date formatting and conditional judgment for the `ExpireTime` (VIP expiration time) field?

In the daily operation of AnQi CMS, we often need to handle time-related fields, such as the VIP expiration time of users (`ExpireTime`).Correctly display this time information and make flexible conditional judgments based on its status, which is crucial for improving user experience and implementing personalized content display.This article will focus on the `ExpireTime` field, discussing in detail how to use the `stampToDate` tag for date formatting, and combine conditional judgment to implement intelligent management of VIP status.###

2025-11-07

How to determine the user's VIP status based on `ExpireTime` in the template and display an expiration reminder or renewal option?

When operating your website, if you provide membership or VIP services, it is crucial for users to clearly understand their VIP status, when it will expire, and how to renew it, as this is essential for improving user experience and member retention.AnQiCMS (AnQiCMS) leverages its flexible template engine and powerful user management features, allowing you to easily implement these functions in website templates.We all know that Anqi CMS is built with a comprehensive user group management and VIP system, which allows us to conveniently set different levels of user permissions and paid content.

2025-11-07

What is the specific function of the `Link` generated by the `userDetail` tag, and how to use it correctly?

AnQi CMS is an efficient and flexible content management system, with its powerful template tag function as the core of dynamic content display.In the daily operation of websites, we often need to display information related to users, such as article authors, member homepages, and so on.At this point, the `userDetail` tag comes into play, and what is particularly crucial is the `Link` (user link) field it generates.

2025-11-07

How to use the `siteId` parameter to call user detail data across sites in multi-site management?

In the multi-site management of AnQi CMS, efficiently sharing and accessing data is the key to improving operational efficiency.Especially in the user system, sometimes we need to display or utilize user details from another site, such as a unified user center, cross-site member privilege display, etc.At this time, the `siteId` parameter provided by AnQi CMS has become a powerful bridge to connect user data across different sites.

2025-11-07