How to display the purchase price and discount price of the user group on the `userGroupDetail` tag on the front-end?

Calendar 👁️ 67

Display the purchase price and discount price of the user group on the AnQiCMS front-end

The strength of AnQiCMS lies in its flexible user group management function for small and medium-sized enterprises and content operators, making it easy to implement paid content and membership services.When we set exclusive purchase prices and discount prices for different user groups, how can we display this information intuitively on the website front end, making it easy for users to understand and thus better guide their purchase decisions?userGroupDetailThe tag is the key tool to solve this problem

UnderstandinguserGroupDetailTag

userGroupDetailThe tag is used to obtain detailed data of a specific user group on the AnQiCMS front-end.Through it, we can call the name, introduction, level of the user group, and most importantly - the purchase price and discount price.

The usage of this tag is very direct:{% userGroupDetail 变量名称 with 参数="值" %}Where you can specify a variable name (such asvipGroup) to receive all the data of the user group, or directly output the value of a specific field.

To obtain information about a specific user group, you need to provide its unique identifier. This can be achieved through two parameters:

  • idThe unique ID of the user group. If you know the numeric ID of the user group (such as, displayed as 1, 2, 3 in the background), you can use this parameter.
  • level: User group level. AnQiCMS may set different levels for user groups (such as Level 1, Level 2, Level 3 VIP), and you can obtain information about the corresponding user group through the level.

In this topic, we focus on two core fields:

  • PriceUsed to obtain the original purchase price of the user group.
  • FavorablePriceUsed to display the discounted price of the user group.

These fields are directly related to the commercial value of the user group, which is the focus we pay the most attention to when displaying on the front end.

Actual application: display the price of the user group

Now, let's look at a specific code example to see how we can flexibly display the original price and discounted price of user groups in a template.

Suppose we have an ID of1The user group named "Basic VIP" has been set with the original price and discount price.

Firstly, we can get the details of the user group through the user group ID:

{# 通过用户组ID获取名为 "vipGroup" 的用户组数据 #}
{% userGroupDetail vipGroup with id="1" %}
    <div class="user-group-info">
        <h3>{{ vipGroup.Title }}</h3> {# 显示用户组名称 #}
        <p>{{ vipGroup.Description }}</p> {# 显示用户组介绍 #}
        <p>用户组等级:{{ vipGroup.Level }}</p> {# 显示用户组等级 #}
        <p>原始购买价格:¥{{ vipGroup.Price }}</p>
        <p>优惠价格:¥{{ vipGroup.FavorablePrice }}</p>
    </div>
{% enduserGroupDetail %}

If you want to retrieve data through user group levels, just need toidparameter withleveland it is done:

{# 通过用户组等级 "2" 获取名为 "level2Group" 的用户组数据 #}
{% userGroupDetail level2Group with level="2" %}
    <div class="user-group-info">
        <h3>{{ level2Group.Title }}</h3>
        <p>原始购买价格:¥{{ level2Group.Price }}</p>
        <p>优惠价格:¥{{ level2Group.FavorablePrice }}</p>
    </div>
{% enduserGroupDetail %}

Skillfully display the discounted price and original price

In practical scenarios, we usually hope to highlight the discounted price prominently when there are discounts, and use a strikethrough to cross out the original price to emphasize the discount力度.At the same time, if a user group does not have a discount price or the discount price is not reasonable (for example, higher than the original price), we should only show the normal price.This can be doneifRealize with conditional judgment tags:

{# 假设我们要展示ID为3的“高级会员”用户组 #}
{% set targetGroupId = 3 %}
{% userGroupDetail premiumGroup with id=targetGroupId %}
    <div class="user-group-card">
        <h2>{{ premiumGroup.Title }}</h2>
        <p class="description">{{ premiumGroup.Description }}</p>
        <div class="price-info">
            {% if premiumGroup.FavorablePrice > 0 and premiumGroup.FavorablePrice < premiumGroup.Price %}
                {# 如果存在有效优惠价,则显示原价(删除线)和优惠价 #}
                <span class="original-price">原价:<del>¥{{ premiumGroup.Price }}</del></span>
                <span class="discount-price">优惠价:<strong>¥{{ premiumGroup.FavorablePrice }}</strong></span>
                {# 还可以计算节省金额,这里利用 `add` 过滤器实现减法,注意负数用法 #}
                <p class="saving-tip">立省 ¥{{ premiumGroup.Price|add:-premiumGroup.FavorablePrice }}!</p>
            {% else %}
                {# 没有优惠价或优惠价无效,只显示正常购买价格 #}
                <span class="normal-price">购买价格:<strong>¥{{ premiumGroup.Price }}</strong></span>
            {% endif %}
        </div>
        <button class="buy-button">立即购买</button>
    </div>
{% enduserGroupDetail %}

In this code block:

  • We first pass throughidObtained user grouppremiumGroupDetails.
  • Next, use{% if ... %}Tag judgmentFavorablePriceIs greater than 0 (ensure there is a discount) and less thanPrice(ensure it is a real discount).
  • If the conditions are met, the original price will be displayed at the same time (using<del>tag to add a strikethrough) and a prominent discount price.
  • If the condition is not met, only the original purchase price will be displayed.
  • By{{ premiumGroup.Price|add:-premiumGroup.FavorablePrice }}This method, utilizesaddThe filter to perform subtraction operations, calculates the amount saved by the user.

By flexible applicationuserGroupDetailLabel, you can clearly and accurately display the purchase price and discount price of the user group on the AnQiCMS front-end, effectively guide users to make purchase decisions, and better achieve the goals of content monetization and member service operation.


Frequently Asked Questions (FAQ)

1. How to ensureuserGroupDetailThe label can correctly obtain user group data?

The most critical thing to ensure that the label can correctly obtain data is to provide the correctidorlevelParameters. On the AnQiCMS backend user group management interface, you can view the ID and level of each user group.Make sure to use actual IDs or Levels in the template.If the data is not displayed correctly, first check whether these parameters are consistent with the background configuration.

2. What will be displayed on the front end if the user group has not set a discount price?

If the back end has not set a discount price for the user group, FavorablePriceThe field usually returns 0 or an empty value. In the above example, we used the `

Related articles

How to obtain the name and description of a specified user group by user group ID in AnQi CMS template?

In AnQi CMS template development, we often need to display different content based on specific conditions, or extract specific information from the system.User group management is a core function of Anqi CMS, which allows us to classify and control website users in a fine-grained manner.When you need to obtain the name and introduction based on the user group ID, Anqi CMS provides a concise and efficient template tag to achieve this goal.

2025-11-07

Can the `userGroupDetail` tag accurately determine through the `Level` (level) of the user group

AnQiCMS where the `userGroupDetail` tag accurately locates user levels: the key to personalized content operation In today's increasingly refined era of content marketing, providing personalized content experiences for different user groups has become an important strategy to enhance user satisfaction and conversion rates.AnQiCMS is a powerful enterprise-level content management system that provides many conveniences in this regard.Among these, the user group management feature is the core of achieving this goal. Today

2025-11-07

How does the `userGroupDetail` tag display the `Title` (name) and `Description` (description) of the user group?

AnQiCMS (AnQiCMS) leverages its flexible and powerful template tag system to provide great convenience to website operators.In daily user management and content operations, we often need to display different information based on the user's identity or permissions.The User Group (User Group) serves as a core permission management mechanism in AnQiCMS. Its name and description are crucial for clearly communicating the rights, services, or identity positioning to the users.

2025-11-07

How to use the `userGroupDetail` tag to retrieve and display the `Id` (ID) of a specified user group?

In AnQi CMS, sometimes we may need to retrieve and display the unique identifier (ID) of a specific user group, such as for conditional judgment in templates, or adjusting page content based on user group ID.The `userGroupDetail` tag provided by AnQi CMS makes it convenient for us to easily obtain detailed information about user groups, including their ID.User group management is one of the core features of Anqicms, which allows us to group users and define different permission levels, even supporting paid content and membership services.

2025-11-07

How to use the `userGroupDetail` tag to parse and utilize the user group's `Setting` key-value pair data?

AnQiCMS (AnQiCMS) provides a powerful and flexible user group management function, which not only helps us finely divide user permissions, but also enables content monetization and member services through the VIP system.Behind these features, the `userGroupDetail` tag plays an important role, it helps us to get detailed information about the user group, among which the most flexible and valuable part is the `Setting` key-value pair data of the user group.

2025-11-07

In the template, what is the difference between the `id` and `level` parameters of the `userGroupDetail` tag, and how do I choose to use them?

In AnQi CMS template development, the `userGroupDetail` tag is an important tool for obtaining detailed information about a specific user group.When we need to display the user group name, description, level, or settings on the page, this tag is used.During use, you may notice that it provides the `id` and `level` parameters to specify the user group to be queried, so what is the difference between them and how should they be chosen?

2025-11-07

How to ensure that the `userGroupDetail` tag returns the correct context of the current page?

Running a website on AnQi CMS, flexibility and accuracy are crucial.Especially when we need to display content based on user identity or specific requirements, ensuring that the user group data obtained matches the context of the current page is the basis for personalized experience and permission control.Today, let's delve into how to make full use of the `userGroupDetail` tag to ensure that we can always obtain the correct user group data.

2025-11-07

How to make conditional judgments in the template using the `userGroupDetail` tag to get the user group level (`Level`)?

When managing users and content in AnQiCMS, we often encounter the need to display different content based on user identity, such as exclusive articles that only VIP members can watch, or different function buttons that users of different levels can see.At this time, the `userGroupDetail` tag and the user group level (`Level`) it retrieves become the key tool for us to implement conditional judgment in the template.AnQiCMS as a flexible and efficient content management system, its template engine provides friendly support for Django template syntax

2025-11-07