In AnQi CMS, sometimes we may need to retrieve and display the unique identifier (ID) of a specific user group, such as for conditional judgments in templates or adjusting page content based on user group ID. AnQi CMS provides convenientuserGroupDetailLabel, allowing us to easily obtain detailed information about the user group, including its ID.

User group management is one of the core functions of Anqi CMS, allowing us to group users and define different permission levels, even supporting paid content and membership services.It is particularly important to understand the ID of a specific user group in these scenarios.

UnderstandinguserGroupDetailTag

userGroupDetailThe tag is used to obtain detailed data for a single user group. Its basic usage requires us to specify which user group's information we want to obtain.To get the user group ID, we mainly usename="Id"This parameter. At the same time, we need to go throughidorlevelParameter to specify which user group it is.

This tag's structure is usually like this:{% userGroupDetail 变量名称 with name="字段名称" id="用户组ID" %}

Among them:

  • 变量名称This is an optional parameter, if you want to assign the obtained ID to a variable for subsequent complex logic, you can define a variable name here.
  • name="字段名称": Specify which field of the user group you want to retrieve. To get the user group ID, we usename="Id".
  • id="用户组ID": Specify by the unique ID set in the background of the user group.
  • level="用户组等级": If you know the user group level (for example, the background may define a level 1 general member group, a level 2 VIP group), you can also go throughlevelparameter.idandlevelThese two parameters are usually optional.

Get the ID of the specified user group

If we want to get the ID of the administrator user group with ID 1, we can use it directly in the template like thisuserGroupDetailTags:

<div>管理员用户组的ID是:{% userGroupDetail with name="Id" id="1" %}</div>

If we know the level of a user group is 2 (for example, this is the level of VIP members), and we want to get its ID, we can do this:

<div>VIP会员用户组的ID是:{% userGroupDetail with name="Id" level="2" %}</div>

This will directly display the ID of the corresponding user group on the page.

Store the user group ID in a variable.

In practice, we often need to store the user group ID obtained into a variable so that it can be used for judgment or combination in other parts of the template. We can set up auserGroupDetailSpecify a variable name to achieve this.

For example, we want to get the user group ID of the user with ID 5 and store it in a namedtargetGroupId:

{% userGroupDetail targetGroupId with name="Id" id="5" %}
<p>我们关注的用户组ID是:{{ targetGroupId }}</p>

Once the ID is assigned totargetGroupIdVariables, we can use them freely in the subsequent template logic. For example, we can combineifLogical judgment tags, display different content based on this ID:

{% userGroupDetail vipGroupId with name="Id" level="2" %}
{% if vipGroupId %}
    <p>VIP用户组的ID是:{{ vipGroupId }}。</p>
    {# 可以在这里添加只有VIP用户组ID存在时才显示的内容 #}
{% else %}
    <p>未找到等级为2的VIP用户组。</p>
{% endif %}

In this way, we can not only obtain the ID of the user group, but also flexibly integrate it into the dynamic display logic of the template, providing more possibilities for the website's user experience and functional implementation. Whether it is to control the content display accurately or to facilitate debugging and management,userGroupDetailTags are a very practical tool.


Frequently Asked Questions (FAQ)

1. If specifiedidorleveldoes not exist,userGroupDetailwhat will the tags return?If specified in the tagidorlevelThe corresponding user group does not exist,userGroupDetailtags are being retrievedIdThe content will not be returned (or returned 0, depending on the specific template environment processing), and the corresponding position on the page will be displayed as empty. It is best to combine it withifJudgment of the statement to avoid displaying blank or error information.

2. In addition to getting the ID, can I useuserGroupDetailTags to get other information of the user group?Of course you can.userGroupDetailThe tag supports retrieving multiple fields of user groups. Just replacenamethe value of the parameter with the field name you need, for examplename="Title"You can get the name of the user group,name="Description"Get the introduction of the user group,name="Level"Get the level of the user group,name="Price"Get the purchase price and so on.

3. How do I know the level of the user groupidorlevelis the value?This information is usually accessible in the 'User Group Management' module of the AnQi CMS backend.In the user group list, each user group will display its unique ID and level.When creating or editing a user group, you can also customize these values.