How to display a user or user group in the template

Calendar 👁️ 73

In Anqi CMS template design, it is crucial to be able to flexibly display user or user group information, which is essential for building personalized, interactive website experiences.AnQi CMS provides intuitive and powerful template tags, allowing you to easily display users' profiles, user groups, and other rich information on the website front-end, thereby enhancing user engagement and the professionalism of the website.

Whether you want to display users' nicknames and membership levels in the article comment section or hope to show specific content and features based on users' identities or user groups, Anqicms providesuserDetailanduserGroupDetailTags can become your helpful assistant.

1. Get user details:userDetailTag

userDetailThe label is used to obtain detailed information about a single user. It allows us to accurately extract a user's data based on a user ID or current context (such as the currently logged-in user).

Basic usage

In general, if you want to display information about the currently logged-in user, it is usually not necessary to explicitly specify the user ID. The system will automatically recognize the context of a logged-in user. If you need to retrieve information about a specific user, such as through the ID of a commenter, you will need to go throughidParameters are used to specify the user ID.

The basic structure is as follows:{% userDetail 变量名 with name="字段名称" id="用户ID" %}

User fields that can be retrieved

userDetailTags provide very rich fields, covering the core information of users, you can use them tonameSpecify the parameter to indicate the specific content to be retrieved:

  • User ID (Id): The unique identifier of the user.
  • Username (UserName): Usually the username or nickname.
  • Real name (RealName): The real name of the user (if provided).
  • User avatar (AvatarURL,FullAvatarURL): The avatar address set by the user,FullAvatarURLMay provide the full path.
  • User email (Email): The user's registration email.
  • User phone number (Phone)User's phone number.
  • User group ID (GroupId): The unique ID of the user's group.
  • Is the user a distributor (IsRetailer): A boolean value indicating whether the user has a distributor status.
  • Account balance (Balance): The available funds in the user's account.
  • Total earnings (TotalReward): The cumulative income earned by the user through the platform.
  • Invitation code (InviteCode): The exclusive invitation code of the user.
  • Last login time (LastLogin): The timestamp of the last login of the user, which needs to be accessed throughstampToDateThe filter performs formatted display.
  • VIP expiration time (ExpireTime): The timestamp of the user's VIP status needs to be formatted as well.
  • User link (Link)指向用户个人主页或其他相关页面的链接。

示例:在页面顶部展示登录用户信息

Assuming we want to display the current logged-in user's avatar, nickname, and expiration information based on their VIP status in a certain area of the website.

”`twig {# Check if the user is logged in, usually by checking if the user ID exists #} {% userDetail currentUserId with name=“Id” %} {% if currentUserId %}

<div>
    {# 获取并显示用户昵称 #}
    {% userDetail userName with name="UserName" %}
    <p>欢迎您,{{ userName }}!</p>

    {# 获取并显示用户头像,如果未设置则显示默认头像 #}
    {% userDetail userAvatar with name="AvatarURL" %}
    {% if userAvatar %}
        <img src="{{ userAvatar }}" alt="{{ userName }}的头像" style="width: 50px; height: 50px; border-radius: 50%;">
    {% else %}
        <img src="/static/images/default-avatar.png" alt="默认头像" style="width: 50px; height: 50px; border-radius: 50%;">
    {% endif %}

    {# 获取用户组ID,以便进一步获取用户组信息 #}
    {% userDetail userGroupId with name="GroupId" %}
    {% if userGroupId %}
        {# 通过用户组ID获取用户组的名称,假设用户组ID为1的用户组是“VIP会员” #}
        {% userGroupDetail userGroupTitle with name="Title" id=userGroupId %}
        <p>您的身份:{{ userGroupTitle }}</p>

        {# 获取

Related articles

How can language switch links be displayed in multilingual sites?

Build a website for global users, multilingual support is an indispensable part.AnQiCMS was designed with this in mind, providing a powerful and flexible solution for the publication and management of multilingual content.By making some simple configuration and template adjustments, we can easily implement language switching functionality on the website, allowing users of different languages to smoothly browse the website content.### AnQiCMS' multilingual capabilities AnQiCMS is inherently equipped with excellent multilingual content management capabilities

2025-11-08

How to enable and display captcha in the comment or message form?

In website operation, the message and comment functions are important channels for interacting with users and collecting feedback.However, this is often accompanied by the困扰 of spam and malicious flooding.To effectively filter out this unnecessary content, enabling the captcha mechanism has become a simple and efficient solution.AnQiCMS (AnQiCMS) provides us with a flexible way to easily integrate captcha functionality into comment or message forms. Next, we will learn in detail how to enable and display the captcha in Anqi CMS.### Step 1: Turn on captcha feature in the management background First

2025-11-08

How to add structured data (JSON-LD) in the HTML header to improve search result display?

In today's highly competitive online environment, it is crucial to make your website content stand out in search engine results pages.In addition to high-quality content and an excellent keyword strategy, structured data (especially in JSON-LD format) plays an increasingly important role.It can help search engines understand the information on your page more accurately, so that your content may be displayed in richer, more attractive forms in search results (such as rich media summaries, i.e., Rich Snippets).What is JSON-LD and why should it be used

2025-11-08

How to deploy multiple AnQiCMS sites on the same server and ensure their independent display?

Deploying multiple websites on the same server while ensuring that they run and display independently is a common need for many content operators.For AnQiCMS users, this is not only feasible but also very efficient.The Anqi CMS leverages its powerful multi-site management features, allowing you to easily manage multiple brand sites, sub-sites, or content branches with just one core program.Next, we will discuss in detail how to deploy and manage multiple security CMS sites cleverly on the same server, so that they operate independently without interfering with each other.### Core Concept

2025-11-08

How can you accurately convert a numeric string to a floating-point number in the Anqi CMS template?

In AnQi CMS template development, we often need to handle various types of data, where the conversion between numeric strings and floating-point numbers is a common and important requirement.For example, you may get a custom field from the background, such as a price (like "12.50"), or a numeric product inventory (like "100"), when performing mathematical operations, comparing sizes, or displaying in a specific format in the template, it is particularly important to convert it from a string type to a floating-point number accurately

2025-11-08

What value will the `float` filter return when encountering a non-numeric string?

In AnQi CMS template development, filters are an important tool for processing and formatting data.They can help us present the data passed from the backend in a way that is more in line with the front-end display requirements.Among them, the `float` filter is specifically used to convert numbers to floating-point format.However, when it encounters a non-numeric string, its behavior becomes particularly critical because it directly affects the accuracy of the template output and the stability of the program.The core function of the `float` filter is to convert the input value to a floating-point number type

2025-11-08

How does AnQiCMS convert user input numeric text to integer type?

In website content management, we often encounter situations where we need to handle digital information, such as product inventory quantities, article reading volumes, and ages submitted by users, etc.These numbers may exist in text form during back-end entry, but when it comes to actual calculations, sorting, or display, we need to ensure that they are true numeric types, not mere text strings.AnQiCMS as a rich-featured enterprise-level content management system, fully considering this point, has provided us with a flexible solution to deal with the need for this kind of data type conversion.###

2025-11-08

What does the `integer` filter default to return when a numeric string cannot be converted to an integer?

In AnQiCMS template development and content operation, we often need to format and convert the data displayed on the page.The filter is an indispensable tool to achieve this goal. Among them, the `integer` filter plays an important role in processing numeric data due to its practical function of converting string values of numeric types into integers.However, when faced with uncertain data sources, a common issue is: what does the `integer` filter default to return when a numeric string cannot be successfully converted to an integer?When building a website using AnQiCMS

2025-11-08