AnQiCMS (AnQiCMS) provides a powerful and flexible user group management feature, which not only helps us to finely divide user permissions, but also enables content monetization and member services through the VIP system. Behind these features, ...userGroupDetailTags play an important role, they can help us obtain detailed information about user groups, and the most flexible and valuable part in terms of application is the user group'sSettingkey-value data.
Today, let's talk about how to cleverly useuserGroupDetailtags, parse, and fully utilize the user group'sSettingkey-value pairs to bring more possibilities to our website.
Get to knowuserGroupDetailTag
userGroupDetailThe main function of the tag is to obtain detailed information about a specific user group.It is like a query tool, by entering the user group ID or level, you can return all the preset data of this user group.
The label's usage is very intuitive:{% userGroupDetail 变量名称 with name="字段名称" id="1" %}. Among them,idThe parameter is used to specify the unique identifier for the user group, or you can also uselevelParameters to specify the level of the user group. These two parameters are usually chosen one at a time to accurately locate the user group you want to obtain information about.
userGroupDetailCan provide various information about the user group, such as the user group's.Id/Title(Name),Description(Introduction),Level(Level),Price(Purchase price) as wellFavorablePriceDiscount prices, etc. And the focus of what we are concerned about today is one namedSettingfield.
In-depth analysisSettingkey-value data
SettingThe field is a very powerful custom configuration item in the user group details.It allows us to store a series of custom key-value pairs of data in the background for each user group, which can be any information that needs to be flexibly configured, such as exclusive privileges, functional limitations, display styles, and so on.For example, you can set a 'special discount' or 'download limit' for the VIP user group.
When we are in the background user group management interface, we add key-value pairs for a user group,Settingsuch as keys forvipDiscountwith a value of0.8; key isexclusiveServicewith a value oftrue), these pieces of information are stored in the user group.Settingin the field.
How to obtainSettingdata
To obtainSettingData, we first need to pass throughuserGroupDetailLabels to obtain the overall information of the user group, and then access through dot syntax (.) to accessSettingfield.
Assuming we want to retrieve all the information of the user group with ID 1 and assign it togroupInfothe variable, we can write it like this:
{% userGroupDetail groupInfo with id="1" %}
{# 现在 groupInfo 变量包含了用户组的所有信息 #}
<div>用户组名称:{{ groupInfo.Title }}</div>
<div>用户组等级:{{ groupInfo.Level }}</div>
{# 获取 Setting 键值对数据 #}
{% set groupSetting = groupInfo.Setting %}
{# 此时,groupSetting 变量就包含了用户组的所有自定义设置 #}
{% enduserGroupDetail %}
In this code, we assigned the obtained user group details togroupInfovariable. Then, by{% set groupSetting = groupInfo.Setting %}This line of code, we putSettingAll the key-value pairs in the field extracted togroupSettingThis new variable, for ease of use later.
How to utilizeSettingkey-value pair
Once we getgroupSettinga variable, it usually exists in an accessible object form, and we can directly access the predefined keys through dot notation.
For example, if you have configured the following key-value pairs in a user group in the background,Settingthe following key-value pairs:
- Key:
vipDiscountValue:0.9(indicating a 10% discount) - Key:
exclusiveIconValue:/static/images/vip_icon.pngRepresents the path of the exclusive VIP icon - Key:
maxDownloadsValue:100Represents the maximum daily download amount
Then in the template, you can access these data directly like this:
{% userGroupDetail groupInfo with id="1" %}
{% set groupSetting = groupInfo.Setting %}
<h3>{{ groupInfo.Title }} 专属特权:</h3>
<ul>
<li>专属折扣:{{ groupSetting.vipDiscount * 100 }}%</li>
<li>
专属图标:
{% if groupSetting.exclusiveIcon %}
<img src="{{ groupSetting.exclusiveIcon }}" alt="{{ groupInfo.Title }}图标" style="width: 30px; height: 30px;" />
{% else %}
无专属图标
{% endif %}
</li>
<li>每日最大下载量:{{ groupSetting.maxDownloads }} 次</li>
<li>是否拥有专属客服:
{% if groupSetting.hasExclusiveSupport == true %}
是
{% else %}
否
{% endif %}
</li>
</ul>
{% enduserGroupDetail %}
In this way, we can easily display the user group privileges configured on the backend on the frontend page. Whether it's showing different badges, discount information, or providing different feature entry points based on user groups,SettingPairing provides great flexibility.
Practical scenarios and value
UtilizeuserGroupDetailTags andSettingPairing data, you can implement many practical website functions:
- Personalized member benefits display: On the user center page, dynamically display exclusive discounts, bonus points, and advanced feature access rights based on the user's membership level.
- Dynamic feature switchSome features (such as AI writing, advanced filtering) can be configured in
Setting, and only users from specific user groups can see or use them. - Multilingual content or style customizationConfigure different welcome messages, image paths, or CSS classes for user groups of different languages to achieve a more refined multilingual site experience.
- Refine content access permissions: Combine the user's current group to obtain its
Settingcontent access permission configuration to determine whether to display or hide certain sensitive content.
SettingThe flexible application of key-value pairs makes the user group function of Anqi CMS no longer just simple permission control, but also becomes a powerful engine that drives personalized services and content monetization on the website.
Summary
userGroupDetailtags and theirSettingThe key-value feature has brought great convenience and extensibility to Anqi CMS users.By calling the simple template tags, we can easily obtain and utilize the various custom data configured by the background for user groups, thus realizing richer, smarter website content display and user experience.Mastery of this feature will add infinite possibilities to your website's operational strategy.
Frequently Asked Questions (FAQ)
SettingWhat types of data can be stored in the field?SettingFields are typically stored as string key-value pairs, but when parsed by a template engine, it attempts to convert them into accessible structures (such as Go