How to display user group details, user avatar, username, and other personal information in the template?

Calendar 👁️ 84

In website operations, providing personalized experiences for users, enhancing community interaction, and clearly displaying the rights and interests of different user groups is the key to increasing user stickiness and website value.AnQiCMS as a powerful content management system provides flexible template tags, allowing us to easily display users' personal information (such as username, avatar) and details of the user groups they belong to on the front-end page.

This article will deeply explore how to use AnQiCMS template tags to display these dynamic information, helping you build a more attractive and interactive website.


First, obtain and display user personal information

In the AnQiCMS template system,userDetailThe tag is a tool for obtaining user personal information. Whether you want to display user information on the user's personal center page, next to the article author information, or in the comments section, this tag can come in handy.

userDetailThe basic usage of tags is:{% userDetail 变量名称 with name="字段名称" id="用户ID" %}. Among them,idThe parameter is required, it specifies the specific user you want to query.

1. Display username and avatar

Username and profile picture are the most common elements of personal information display. Suppose we want to display the username and profile picture of the user with ID 123:

{% set userId = 123 %} {# 假设这是您要展示的特定用户ID #}

{% userDetail userInfo with id=userId %}
{% if userInfo %}
    <div class="user-profile">
        <img src="{{ userInfo.AvatarURL }}" alt="{{ userInfo.UserName }}的头像" class="user-avatar">
        <span class="user-name">{{ userInfo.UserName }}</span>
    </div>
{% else %}
    <span class="guest-name">匿名用户</span>
{% endif %}

In the above example:

  • We first pass through{% set userId = 123 %}Set a user ID to be queried. In practice, thisuserIdmay come from the author ID of the current article, the ID of the comment publisher, or obtained through URL parameters.
  • {% userDetail userInfo with id=userId %}Set the user ID touserIdAssign the detailed information touserInfoVariable.
  • userInfo.AvatarURLWill display the user's avatar image address. If you need a full-size avatar, you can useuserInfo.FullAvatarURL.
  • userInfo.UserNameThen directly output the user's nickname.
  • We also added one{% if userInfo %}Judgment, in case the user does not exist, it can display 'Anonymous User' or other alternative information to ensure page stability.

2. Get more user details

userDetailTags support the acquisition of various personal information fields, allowing you to enrich the display content as needed:

  • userInfo.RealName: The real name of the user.
  • userInfo.Introduce: The personal introduction of the user.
  • userInfo.EmailUser's email address.
  • userInfo.PhoneUser's phone number.
  • userInfo.LinkUser's personal homepage link (if provided).
  • userInfo.LastLoginTimestamp of user's last login, which needs to be processed throughstampToDateformatted.

For example, display more detailed information about the user on the personal center page:

{% set currentUserId = 456 %} {# 假设这是当前登录用户的ID #}

{% userDetail profileInfo with id=currentUserId %}
{% if profileInfo %}
    <div class="user-detail-card">
        <h2>{{ profileInfo.UserName }} 的个人资料</h2>
        <img src="{{ profileInfo.FullAvatarURL }}" alt="{{ profileInfo.UserName }}的头像" class="profile-avatar large">
        <p>真实姓名: {{ profileInfo.RealName }}</p>
        <p>邮箱: {{ profileInfo.Email }}</p>
        <p>联系电话: {{ profileInfo.Phone }}</p>
        <p>个人简介: {{ profileInfo.Introduce }}</p>
        <p>最近登录: {{ stampToDate(profileInfo.LastLogin, "2006-01-02 15:04") }}</p>
        <a href="{{ profileInfo.Link }}" class="user-homepage-link">访问我的主页</a>
    </div>
{% else %}
    <p>抱歉,未找到该用户的信息。</p>
{% endif %}

2. Display user group details

AnQiCMS supports user group management, different user groups may represent different membership levels or permissions.userGroupDetailTags allow us to display detailed information about these groups.

userGroupDetailThe usage of the label is:{% userGroupDetail 变量名称 with name="字段名称" id="用户组ID" %}or{% userGroupDetail 变量名称 with name="字段名称" level="用户组等级" %}.id(The unique identifier of the user group) orlevel(The level of the user group), either one.

1. Display the name of the user's group.

We usually get the user firstGroupIdThen we use this ID to query the details of the user group. Here is an example of combining the two:

`twig {% set userId = 123 %} {# Again assuming this is the user ID to be queried #}

{% userDetail userWithGroupInfo with id=userId %} {% if userWithGroupInfo %}

<div class="user-badge">
    <img src="{{ userWithGroupInfo.AvatarURL }}" alt="{{ userWithGroupInfo.UserName }}的头像" class="small-avatar">
    <span class="username">{{ userWithGroupInfo.UserName }}</span>

    {% userGroupDetail groupDetails with id=userWithGroupInfo.GroupId %}
    {% if groupDetails %}
        <span class="group-title">{{ groupDetails.Title }}</span>
        <span class="group-level">LV.{{ groupDetails.Level }}</span>
        {% if groupDetails.Description %}
            <span class="group-description

Related articles

How to customize Json-LD structured data to enhance search engines' understanding and display of page content?

In today's highly competitive online environment, making website content stand out, being accurately understood by search engines, and presented in an attractive manner is a goal that every website operator diligently seeks.Among them, the structured data of Json-LD plays a vital role.

2025-11-08

How to retrieve and display custom contact information from the background in a template (such as phone, email, WeChat)?

In website operation, clearly displaying contact information is crucial for improving user experience and promoting business communication.Whether it is customer consultation, seeking support, or business cooperation, visitors hope to find and contact you quickly.AnQiCMS provides a convenient and efficient mechanism for you to centrally manage these contact information in the background, and dynamically display them in the website template without frequently modifying the code, which greatly improves the efficiency of website maintenance.### Contact Management in AnQiCMS On AnQiCMS backend

2025-11-08

How to display the current year or a specified format of time in a template, such as "2023-10-26 15:30:00"?

In website operation, it is often necessary to dynamically display the current year or a specific date and time format at different positions on the page, whether it is used for the copyright statement in the footer, the publication update time of articles, or the time points of various events.AnQiCMS (AnQiCMS) provides flexible and powerful template tags, allowing you to easily meet these needs.

2025-11-08

How to call the embedded method of Go structure in AnQiCMS template to get and display data?

AnQiCMS with its efficient architecture based on the Go language and flexible template system, provides strong support for website content display.For users who want to implement more intelligent and dynamic content display in templates, it is particularly important to understand how to call the built-in methods of Go structures in AnQiCMS templates.This can make your template more tidy, and it can encapsulate complex logic processing on the backend, allowing the frontend to focus more on visual presentation.

2025-11-08

How to customize the overall layout and display structure of the website front-end page in AnQi CMS?

## Flexible Mastery: How Anqi CMS Creates Personalized Website Front-end Layout and Display Structure In the digital age, the front-end design of a website is crucial for user experience and brand image.An efficient content management system that not only can easily manage content but also can flexibly customize the overall layout and display structure of the front-end page.AnQi CMS is well-versed in this, providing us with a powerful and intuitive toolkit that makes website customization accessible.

2025-11-08

How to set a dedicated display template for articles, products, or single pages in AnQi CMS?

In Anqi CMS, in order to make your website content more personalized and visually appealing, you can set exclusive display templates for different types of articles, product detail pages, or independent single pages.This can not only improve the user experience, but also facilitate differentiated operation for specific content.The Anqi CMS provides a flexible mechanism to achieve this goal, whether it is for all content under a specific category, a specific article or product, or an independent page, you can find a suitable template customization solution.

2025-11-08

What types of template display modes does AnQi CMS support (such as adaptive, code adaptation)?

How to ensure that the content is perfectly displayed on different devices when building a website is a problem that every operator needs to consider.A safe CMS knows this, therefore it provides various flexible template display modes to help us choose the most suitable website presentation method according to our actual needs. The template display mode of AnQi CMS mainly includes three types: adaptive, code adaptation, and independent PC + mobile site.Understand their respective features and application scenarios, which can help you better plan the user experience and SEO strategy of the website.

2025-11-08

How to ensure that template files do not display乱码 when displayed on the page in AnQi CMS?

When using AnQi CMS to manage website content, if you suddenly find that the text on the page becomes strange and turns into unreadable symbols, which is what we often call 'garbled code', it is undoubtedly very annoying.The root cause of page garbled characters is usually inconsistent file encoding and browser parsing encoding.In Anqi CMS, ensure that template files are displayed normally, avoid garbled text, and the key is to understand and correctly handle the encoding of template files.The AnQi CMS has specific requirements for the encoding of template files, it needs to use **UTF-8 encoding** uniformly

2025-11-08