AnQiCMS (AnQiCMS) provides powerful and flexible user group management functions, which not only helps us to finely divide user permissions, but also enables content monetization and member services through the VIP system. Behind these functions, userGroupDetailLabels play an important role, they can help us obtain detailed information about user groups, and the most flexible and valuable part is the user group'sSettingkey-value data.
Today, let's talk about how to cleverly useuserGroupDetailtags, parse and make full use of user groupsSettingkey-value data, bringing more possibilities to our website.
KnowuserGroupDetailtags
userGroupDetailThe primary function of the label is to obtain detailed information of a specific user group.It is like a query tool, by entering the user group ID or level, it can return all the preset data of this user group.
The usage of this label is very intuitive:{% userGroupDetail 变量名称 with name="字段名称" id="1" %}.idThe parameter is used to specify the unique identifier of the user group, or you can also uselevelThe parameter is used 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'sId/Title(Name),Description(Description),Level(Level),Price(Purchase Price) as well asFavorablePrice(Discount Price) etc. And the focus of our attention today is one namedSettingfield.
Deep AnalysisSettingkey-value data
SettingThe field is a very powerful custom configuration option in the user group details.It allows us to store a series of custom key-value pairs of data for each user group in the background. This data can be any necessary flexible configuration information, such as exclusive privileges, functional restrictions, display styles, and so on.For example, you can set a 'dedicated discount' or 'download limit' for the VIP user group.
When we are in the background user group management interface, for a certain user group,Settingwe added a key-value pair (such as key for),vipDiscountwith a value of0.8; key for"),exclusiveServicewith a value oftrue), these pieces of information are stored in the user group,Settingfield in.
How to getSettingdata
To getSettingData, we first need to obtainuserGroupDetaillabels to get the overall information of the user group, then through the dot syntax.) to accessSettingfield.
Assuming we want to get 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 block, we assigned the user group details obtainedgroupInfoto a variable. Then, through{% set groupSetting = groupInfo.Setting %}This line of code, we assignSettingAll key-value pairs of the field were extracted togroupSettingthis new variable for subsequent use.
How to make use ofSettingThis is the key-value pair
Once we get itgroupSettingThe 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 in a user group in the background:SettingThe following key-value pairs have been configured:
- Key:
vipDiscountValue:0.9(indicating a 10% discount) - Key:
exclusiveIconValue:/static/images/vip_icon.png(Represents the path of the exclusive VIP icon) - Key:
maxDownloadsValue:100(Represents the maximum daily download amount)
Then, in the template, you can directly access these data 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 %}
Through this method, we can easily display the user group privileges in the backend on the frontend page. Whether it is to display different badges, discount information, or provide different feature entries based on the user group,SettingThe key-value pairs provide great flexibility.
Practical scenarios and value
UtilizeuserGroupDetailTags andSettingWith key-value pair data, you can implement many practical website functions:
- Display personalized member benefitsIn the user center page, according to the user's membership level, dynamically display their exclusive discounts, points multiplier, and advanced feature access permissions.
- Dynamic feature switch:Certain features (such as AI writing, advanced filtering) can be configured in
Settingwhere only users from specific user groups can see or use them. - multi-language content or style customization:Configure different welcome messages, image paths, or CSS classes for user groups in different languages to achieve a more refined multilingual site experience.
- Refined content access permissionsEnglish translation: : Combine the user's current user group to obtain its
Settingcontent access permission configuration to determine whether to display or hide some sensitive content.
SettingThe flexible application of key-value pairs makes the user group function of the security CMS no longer just simple permission control, but also becomes a powerful engine driving the individualization of website services and content monetization.
Summary
userGroupDetailTags and theirSettingKey-value feature, bringing great convenience and extensibility to Anqi CMS users.Through simple template tags, we can easily obtain and utilize the various custom data configured for user groups by the backend, thus achieving richer, more intelligent website content display and user experience.Proficiently mastering this feature will add infinite possibilities to your website operation strategy.
Common Questions (FAQ)
SettingWhat types of data can be stored in the field?SettingFields are typically stored in string format as key-value pairs, but when the template engine parses them, it tries to convert them into accessible structures (such as Go