How to display user registration or group details (such as username, level, avatar) on the front page?

Calendar 👁️ 70

In website operation, displaying rich user-related information on the front page is an effective way to enhance user experience and community activity.Whether it is displaying the author's avatar, the user's level, or the username at registration, these personalized details can make the website more vibrant.AnQiCMS as a powerful content management system provides us with very flexible template tags and data call capabilities, making the display of this information easy and simple.

Understand the AnQiCMS user and group data

In the AnQiCMS backend, user data and user group data are independent and interrelated.Each user has unique ID, username, avatar information, and they are also assigned to specific user groups, and each user group also has its own name and level.The information needs to be displayed on the front end, we mainly use the AnQiCMS provideduserDetailanduserGroupDetailthese two template tags.

Display user personal information

To display user details, such as username, avatar, and level, we usually start by fetching user details. Suppose we want to display the information of the currently logged-in user or a specific user.userDetailThe label is our preference.

For example, when displaying author information on a user's personal center page or on an article detail page, we may have already obtained the current user or author's ID in the template context. With this ID, we can then retrieve all the user's information:

{% userDetail userProfile with id=user.Id %}
  <div>
    <h4>用户名:{{ userProfile.UserName }}</h4>
    {% if userProfile.AvatarURL %}
      <img src="{{ userProfile.AvatarURL|thumb }}" alt="{{ userProfile.UserName }}的头像" style="width: 80px; height: 80px; border-radius: 50%;">
    {% else %}
      <img src="/static/images/default-avatar.png" alt="默认头像" style="width: 80px; height: 80px; border-radius: 50%;">
    {% endif %}
    <p>邮箱:{{ userProfile.Email }}</p>
    <p>最近登录时间:{{ stampToDate(userProfile.LastLogin, "2006-01-02 15:04") }}</p>
  </div>
{% enduserDetail %}

In this code block:

  • {% userDetail userProfile with id=user.Id %}It will depend on the contextuser.Idto retrieve the full information of the user and assign it touserProfilethis variable.
  • {{ userProfile.UserName }}directly displays the user's name.
  • {{ userProfile.AvatarURL|thumb }}displays the user's avatar. Here we usethumbA filter that can automatically generate optimized avatar sizes based on the thumbnail configuration in the background content settings, thereby improving page loading speed. If the user has not set an avatar, we also through{% if ... else ... %}Determine whether to display a default avatar.
  • {{ userProfile.Email }}Simply displayed the user's registered email.
  • {{ stampToDate(userProfile.LastLogin, "2006-01-02 15:04") }}Demonstrates how to format a timestamp into a readable date and time.

In this way, we can flexibly retrieve and display various fields of the user profile, such asRealName(Real name),Introduce(Personal introduction) and so on.

Display user group information

User groups are an important feature in AnQiCMS for managing user permissions and identities, such as VIP members, ordinary users, and so on.Each user belongs to a specific user group, and the user group itself also has its name and level.To display the details of the user's group, we first need to obtain the details from the user's informationGroupIdThen useuserGroupDetail.

Continuing with the above example, we can display the user's personal information while obtaining and displaying their group information:

{% userDetail userProfile with id=user.Id %}
  <div>
    <h4>用户名:{{ userProfile.UserName }}</h4>
    <p>邮箱:{{ userProfile.Email }}</p>
    {% if userProfile.GroupId > 0 %} {# 检查用户是否属于某个分组 #}
      {% userGroupDetail groupInfo with id=userProfile.GroupId %}
        <p>用户等级:{{ groupInfo.Title }} (Lv.{{ groupInfo.Level }})</p>
        <p>等级描述:{{ groupInfo.Description }}</p>
      {% enduserGroupDetail %}
    {% else %}
      <p>用户等级:普通用户</p>
    {% endif %}
  </div>
{% enduserDetail %}

Here:

  • We first pass through{% if userProfile.GroupId > 0 %}Determine if the user has been assigned to a specific user group (typically, an ID greater than 0 indicates a valid group).
  • {% userGroupDetail groupInfo with id=userProfile.GroupId %}tags touserProfile.GroupIdAs a parameter, obtain the detailed information of the user group and store it in.groupInfoVariable.
  • We can call it afterwards{{ groupInfo.Title }}and the group name{{ groupInfo.Level }}to display to the front-end users.

Combine the user's personal information with the user group information to display, which can make the content of the page more rich and personalized, for example, displaying the user level of the评论者评论者 in the comments section, or displaying the VIP indicator next to the author's introduction.

Practical skills and precautions

  1. Data security considerations:When displaying user data on the front end, be sure to pay attention to the sensitivity of the information.For example, the user's mobile number, detailed address, or password and other privacy information should not be directly displayed on the front page unless there is a clear business need and the user's consent is obtained.The template design philosophy of AnQiCMS itself also encourages us to call as needed, reducing the risk of sensitive information leakage.
  2. Default value handling:Some users may not have set a profile picture or bio. To avoid blank or incorrect display on the page, we can use AnQiCMS filters to provide default values for missing data. For example,{{ userProfile.Introduce|default:"该用户暂无简介。" }}When the personal introduction is empty, it will display "This user has no introduction.".
  3. Image optimization:User avatars and related images play an important role in website loading speed. In addition to usingthumbFiltering thumbnail processing outside, the "Content Settings" on the AnQiCMS background also provides whether to enable Webp

Related articles

How to automatically convert URLs and email addresses in text to clickable links and display them?

In website content management, we often encounter scenarios where we need to display various links and email addresses in articles or pages.Manually converting this text to clickable HTML links is time-consuming and prone to errors, especially when the amount of content is large, and the workload is惊人的。AnQi CMS fully understands this pain point of users, built-in efficient and intelligent text processing mechanism, can automatically identify and convert URLs and email addresses, greatly improve the efficiency of content publishing and user browsing experience

2025-11-08

How to format a floating-point number to a specified precision (number of decimal places) for display?

In AnQiCMS, the flexibility of content display is one of its core advantages.When dealing with floating-point numbers that require precise display of decimal places, understanding how to utilize its powerful template engine function is particularly important.Ensure that numbers are presented in the expected format for displaying product prices, statistical data, or technical parameters, which can greatly enhance user experience and the professionalism of the website.The Anqi CMS template syntax borrows from the Django template engine, providing rich filters (Filters) to process and format data.Formatting for floating-point numbers

2025-11-08

How to debug the structure, type, and value of display variables in a template to help troubleshoot display issues?

During the template development process of Anqi CMS, we sometimes encounter situations where variables do not display as expected or the displayed content is incorrect.This may affect the normal functioning of the website, and may also cause deviations in content display, reducing the user experience.We need an efficient and intuitive tool to help us quickly locate the problem.The Anqi CMS provides a very practical built-in filter——`dump`, which can help us clearly view the structure, type, and current value of any variable in the template.

2025-11-08

How to retrieve and display specific content from a specified site in a multi-site management environment?

In today's changing network environment, many businesses and content operators are no longer satisfied with a single site.Scenarios where there are multiple brands, product lines, or the need for multilingual promotion are becoming increasingly common.AnQiCMS (AnQiCMS) is exactly under such needs, providing powerful multi-site management capabilities, allowing us to easily manage multiple content platforms with a single system.But having multi-site functionality is not enough. Often, we need to display specific content from one site on another site, to achieve resource sharing and content synergy.For example, the main site wants to display the latest products of a child site

2025-11-08

How to determine if a string, array, or map contains a specific keyword and display the boolean result?

In AnQi CMS template development, we often need to dynamically adjust the display of the page based on the specific attributes or keywords of the content.For example, determine whether an article title contains a certain word, whether a product category is in a certain list, or whether a configuration item exists.The powerful template engine of AnQi CMS provides various filters and operators, which can help us easily implement these judgments and obtain clear boolean (True/False) results.Let's delve deeper into how to implement these flexible judgments in Anqi CMS.### Core Function

2025-11-08

How to calculate the number of times a certain keyword appears in a string or array and display it?

In the daily work of content operation, we often need to conduct in-depth analysis of website content, one of the common requirements is to understand the frequency of a keyword appearing in a specific string or content block.This is crucial for SEO optimization and also helps us evaluate the relevance and quality of the content.AnQi CMS as an efficient enterprise-level content management system provides us with very convenient built-in tools to solve this problem, that is the powerful `count` filter.

2025-11-08

How to remove spaces or specified characters from the beginning, end, or all positions of a string and then display it?

In website content operation, we often encounter situations where strings contain unnecessary spaces or specific characters.These seemingly minor issues may affect the display aesthetics, SEO effects, and user experience of the content.For example, a product title may display differently on different devices due to leading and trailing spaces, or a keyword list may be surrounded by additional symbols, affecting search engine recognition.

2025-11-08

How to implement automatic conversion of uploaded images to WebP format to optimize front-end loading and display speed?

In today's content operation, website loading speed is crucial for user experience and search engine rankings.Images are an important part of web content, and their loading performance is often a key factor affecting overall speed.AnQiCMS (AnQiCMS) is well aware of this and provides a convenient image optimization feature, especially converting images uploaded to WebP format automatically, which can significantly improve the display speed of the website's front-end.### WebP format: A speed booster for front-end loading WebP is an image format developed by Google

2025-11-08