How to display the name and description of user groups in AnQiCMS template?

Calendar 👁️ 66

Display user group names and descriptions flexibly in AnQiCMS templates

AnQi CMS as an efficient content management system, its "User Group Management and VIP System" function provides great convenience for website operators, allowing them to easily implement user classification, content permission control, and value-added membership services.But in actual operation, how to naturally present these carefully designed user group information, such as their names and detailed introductions, on the website front-end template, so that users can clearly understand their identity privileges or exclusive rights to various services, is a demand that template developers and content operators often encounter.

幸运的是,AnQiCMS provides a powerful and intuitive template tag system, we can take advantage of itsuserGroupDetail tags to easily achieve this goal.

UnderstandinguserGroupDetailTag

userGroupDetailIs the template tag specially designed for AnQiCMS to obtain user group details.Its core function is to retrieve and output detailed data of a specified user group based on specified conditions, including its name, introduction, level, etc.

Its basic usage is as follows:

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

Or, if you prefer to get it based on the user group level:

{% userGroupDetail 变量名称 with name="字段名称" level="用户组等级" %}

Here变量名称Optional, if set, you can store the user group information obtained in a variable for repeated use in the subsequent part of the template.name="字段名称"Specify which specific attribute of the user group you want to retrieve, such as name or introduction. When specifying which user group information to retrieve, you can use the user groupid(ID) orlevel(Level) Choose one of these parameters to locate, either one can be used, but not both at the same time.

How to display the user group name (Title) and description (Description)

In AnQiCMS, the name of the user group corresponds toTitlefield, and its detailed introduction corresponds toDescriptionfield.

For example, if you want to display the ID directly in the template as1to write the name of the user group

<p>用户组名称:{% userGroupDetail with name="Title" id="1" %}</p>

Similarly, to display the ID of1Group Introduction:

<p>用户组介绍:{% userGroupDetail with name="Description" id="1" %}</p>

In order to handle and display this information more flexibly, we usually assign the obtained user group details to a variable and then access different properties through this variable. The advantage of this is that you only need to do it onceuserGroupDetailTags, you can get all available fields of the user group, avoiding repeated queries.

{# 假设我们要获取ID为1的用户组的名称和介绍 #}
{% userGroupDetail groupInfo with id="1" %}
{% if groupInfo %}
    <p>用户组名称:<strong>{{ groupInfo.Title }}</strong></p>
    <p>用户组介绍:{{ groupInfo.Description }}</p>
{% else %}
    <p>未找到ID为1的用户组信息。</p>
{% endif %}

If you want to get information through the level of the user group, for example, to get the level of2The details of the user group (usually representing VIP level), just need toidparameter withleveland it is done:

{# 获取等级为2的用户组的名称和介绍 #}
{% userGroupDetail vipGroupInfo with level="2" %}
{% if vipGroupInfo %}
    <p>VIP用户组名称:<strong>{{ vipGroupInfo.Title }}</strong></p>
    <p>VIP用户组介绍:{{ vipGroupInfo.Description }}</p>
{% else %}
    <p>未找到等级为2的用户组信息。</p>
{% endif %}

Application scenarios in practice

  1. Display the user's group in the user center profile page:After the user logs in, we usually display the name and introduction of the user group to which the user belongs in the personal center. This requires first obtaining the user group ID of the currently logged-in user (usually through globaluseror objectuserDetailLabel retrieval), then use the ID to query the user group details.

    {# 假设当前登录用户的用户组ID可通过 {{ user.GroupId }} 获得 #}
    {% if user.GroupId %}
        {% userGroupDetail currentUserGroup with id=user.GroupId %}
        {% if currentUserGroup %}
            <div class="user-group-info">
                <h3>您当前的用户组:{{ currentUserGroup.Title }}</h3>
                <p>{{ currentUserGroup.Description }}</p>
                {# 还可以显示VIP过期时间等,如果userDetail中有相关字段 #}
            </div>
        {% endif %}
    {% else %}
        <p>您目前是普通访客,登录可查看更多权益。</p>
    {% endif %}
    
  2. Display the privileges of a specific user group on the content or service detail page:If your website offers paid content or VIP exclusive services, you can directly display the names and introductions of specific user groups on the corresponding detail page, guiding users to upgrade.

    "twig {# Assume some content

Related articles

How to dynamically add a website name suffix to the page title to optimize SEO display?

In content operation, the page title is undoubtedly the first barrier to attracting the attention of search engines and users.A clear, keyword-rich, and brand-consistent title that not only improves user click-through rate but is also a key element of search engine optimization (SEO).AnQiCMS is an enterprise-level content management and SEO optimization system that provides a flexible and powerful mechanism, allowing you to easily add a website name suffix to the page title, thereby achieving a win-win situation for brand enhancement and SEO.### Unified Brand Image

2025-11-07

How to prevent malicious collection of content in AnQiCMS and affect the exclusivity of front-end content?

Original content is the core value of the website, it condenses our thoughts, time and energy.However, the content has been maliciously collected, plagiarized, and published on other platforms, not only diluting the exclusivity of our content, but also potentially affecting the SEO performance of the website and even damaging the brand image.As website operators, we all hope that our front-end content can maintain its original exclusivity. 幸运的是,AnQiCMS was designed with this pain point in mind from the very beginning, incorporating multiple powerful features to help us effectively prevent content from being maliciously scraped and protect our original value. ### 1. Core Defense

2025-11-07

How to display the reading and comment counts of articles on the front end?

In website operation, the number of article views and comments is an important indicator of content popularity and user interaction.AnQiCMS as a flexible content management system provides a convenient way to display these data on the website front end.By using simple template tags, even without delving into programming, these functions can be easily realized.The AnQiCMS template system borrows the syntax of the Django template engine, using double curly braces `{{variable}}` to output variable content, and using single curly braces and percentages `{% tag %}` to call function tags

2025-11-07

How to use the content model in AnQiCMS to define different content display structures?

AnQiCMS Content Model: The Smart Choice for Creating Flexible and Variable Website Content In the digital age, a website is not just a platform for displaying information, but also a gathering point for diverse content such as corporate brands, product services, and professional knowledge.If always using a fixed display structure for different types of content, the website content is likely to become monotonous and difficult to manage efficiently.AnQiCMS fully understands this, the "Content Model" feature it provides is the core tool to solve this pain point, helping us easily define and manage various unique content display structures.Imagine

2025-11-07

How to control the automatic compression and thumbnail display of AnQiCMS front-end images after uploading?

In the process of operating a website, the management and optimization of image content is a key factor in improving user experience, accelerating website loading speed, and even affecting search engine rankings.AnQiCMS fully considered these needs, providing a flexible image processing mechanism that allows us to easily control the automatic compression and thumbnail display of uploaded images on the front end.### Content Setting: The Core Hub of Image Processing To finely manage the images on the AnQiCMS website, we need to first go to the "Background Settings" menu and then click on the "Content Settings" option

2025-11-07

How to use conditional judgment and loop structures to dynamically display content in AnQiCMS templates?

In AnQiCMS templates, dynamic content display is the core of building interactive and data-driven websites.By using conditional judgment and loop structures, you can flexibly present information based on different data states, or efficiently traverse data sets to generate lists, tables, and other content.AnQiCMS's template engine adopts a syntax similar to Django templates, making these operations intuitive and easy to learn.Next, we will delve into how to effectively use these powerful tools in the AnQiCMS template.### One, conditional judgment

2025-11-07

How to display the table of contents (ContentTitles) in the front-end template?

In the daily operation of websites, especially when publishing long articles, adding a clear table of contents (or content navigation) is crucial for improving user experience.It can not only help visitors quickly understand the structure of the article, conveniently jump to the chapters of interest, but also optimize the page SEO performance to a certain extent.AnQiCMS provides a very practical feature that allows us to easily implement the directory display of article content in the front-end template.### Understanding how AnQiCMS generates article contents AnQiCMS while processing article content

2025-11-07

How to correctly display the `hreflang` tag in a multilingual site for search engine guidance?

In today's globalized digital age, multilingual support has become a basic requirement for websites to reach a wider audience.However, providing different language versions of content is not enough, we also need to ensure that search engines can correctly understand the relationships between these different versions, so that users can be directed to the content most suitable for their language and region.This is where the `hreflang` tag comes into play.For websites built using AnQiCMS, correctly configuring the `hreflang` tag is a key step in improving international SEO performance

2025-11-07