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

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.In these scenarios, understanding the IDs of specific user groups becomes particularly important.

UnderstandinguserGroupDetailtags

userGroupDetailTags are specifically used to retrieve detailed data for a single user group.Its basic usage requires us to specify which user group's information we want to retrieve.name="Id"This parameter. At the same time, we need to go throughidorlevelparameter to explicitly identify which user group.

The structure of this tag 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="字段名称"Here we specify which field of the user group we want to retrieve. To retrieve the user group ID, we usename="Id".
  • id="用户组ID"specified by the unique ID set in the background of the user group.
  • level="用户组等级"If the user group level is known (for example, the background may define a level 1 general member group, a level 2 VIP group), it can also be done throughlevelParameters can be specified.idandlevelThese two parameters are usually chosen one from the other.

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 want to get its ID, we can do it like this:

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

Thus, the ID of the corresponding user group will be displayed directly on the page.

Store the user group ID in a variable.

In practical applications, we often need to store the obtained user group ID in a variable so that it can be used for judgment or combination in other parts of the template.userGroupDetailLabel a variable name to do this.

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

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

Once the ID is assigned totargetGroupIdVariables, we can then freely use it in the subsequent template logic. For example, we can combineiflogic judgment tags, displaying different content according to this ID:

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

By this means, 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 for precise control of content display or for convenient debugging and management, userGroupDetailTags are a very practical tool.


Common Questions (FAQ)

1. If the specifiedidorleveldoes not exist,userGroupDetailwhat will the tag return?If the specified in the tagidorlevelThe corresponding user group does not exist,userGroupDetailtag in retrievingIdThe time will not return any content (or return 0, depending on the specific template environment handling), and the corresponding position on the page will be displayed as empty. It is best to combine it with usage.ifJudging the statement to avoid displaying blank or error information.

2. Besides getting the ID, can I also useuserGroupDetailtags to get other information about the user group?Of course you can.userGroupDetailLabel supports fetching 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, etc.

3. How do I know the level of the user groupidorlevelis??This information is usually visible 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.You can also customize these values when creating or editing a user group.