In the template development of AnQi CMS,userGroupDetailLabels are an important tool for obtaining detailed information about specific user groups.When we want to display the user group name, description, level, or its settings on the page, this tag will be used.During use, you may notice that it providesidandlevelThese two parameters are used to specify the user group to be queried, so what are the differences between them, and how should they be selected for use?

UnderstandinguserGroupDetailTag

First, let's briefly reviewuserGroupDetailThe role of the tag. Its main function is to retrieve all related data of a user group based on a given identifier (which can be a user group ID or user group level), such as the name (Title), introduction (Description), purchase price (Price), etc.This allows template developers to flexibly display exclusive content or features for different user groups on the page.

When calling this tag, you need to go throughnameThe parameter is used to specify the specific fields of the user group to be retrieved, whileidandlevelThe parameter is used to accurately locate which user group.

idParameter: Accurate unique identifier

idParameters usually refer to the unique numeric identifier for a user group within the system.You can imagine it as the 'ID number' for each user group, it is a fixed number that usually does not change and precisely points to a specific user group record in the database.

When to useidparameters:

When you are in the following scenarios, you usually choose to useidparameters:

  • Exactly refer to a known user group:If you know the unique ID of a specific user group and want to directly obtain its information,idIt is the most direct and accurate way. For example, you may have seen the ID of some user group in the background user group management interface and want to hardcode the reference in the frontend template (although hardcoding is not recommended, it may be used for quick testing or referencing built-in fixed user groups sometimes).
  • Associated with other data:When your other data (such as user data) stores the user group ID of the user and you want to query the details of the user group through this ID,idThe parameter is the ideal choice.
  • Strongly associated with backend logic:If some business logic (such as permission judgment, payment function) strictly depends on the unique ID of the user group, then displaying relevant information through the ID in the template will be more stable.

Example usage:If you want to get the name of the user group with ID 1:

<div>用户组ID为1的名称:{% userGroupDetail with name="Title" id="1" %}</div>

levelParameter: Flexible level identifier

levelThe parameter represents the level of the user group, which is usually a string or number with semantic meaning, used to describe the hierarchy or category of the user group.For example, you may have set levels such as “VIP_Level_1”, “VIP_Level_2”, or “General Member”, “Senior Member”, and so on.levelIt may be more than in some casesidmore readable.

When to uselevelparameters:

In the following situations,levelThe parameter will be a better choice:

  • Query by level or role:If your user group is divided according to different membership levels, permission levels, etc., and you want to dynamically display content based on these level names,levelParameters will be very convenient. For example, you want to display the exclusive descriptions for all 'Gold Member' user groups.
  • The template logic is clearer:Using directly in the templatelevel="VIP_Gold"may be more thanid="7"Easier to understand and maintain, especially when you are not familiar with the specific ID relationships.
  • Configuration level system:If your user group hierarchy is configurable in the background (for example, the level names or corresponding permissions may be adjusted), but you want to refer to them by logical names in the template,levelParameters can provide this kind of flexibility.

Example usage:Suppose your system has aVIP_Level_1group level, you want to get its name:

<div>VIP等级为VIP_Level_1的名称:{% userGroupDetail with name="Title" level="VIP_Level_1" %}</div>

idwithlevelOptions and considerations

UnderstoodidandlevelAfter understanding the respective uses, the most important distinction is:These two parameters are mutually exclusive, you cannot use them at the same time.When you calluserGroupDetailWhen labeling, you must and can only chooseidorlevelone of them to specify the user group.

How to choose:

  • Give priority to business semantics:If your template logic is more focused on the 'level' or 'role' concept of user groups, and these level names are relatively stable, then uselevelMake the template code more readable and maintainable.
  • Prioritize stability:If you need to refer to a user group that has fixed and infrequently changing attributes at the system level (for example, a special system administrator group), thenidIt is usually a more stable choice as it is unlikely to change due to business level adjustments.
  • Consider the data source:Which information is easier for you to obtain in the current template context (is it ID or Level string), which will also affect your choice.

In short,idProvided an accurate, immutable unique identifier, suitable for strictly and directly referencing user groups; andlevelIt provides a more semantic and hierarchical identification, suitable for dynamically displaying content based on the roles or levels of user groups. Choose reasonably according to your specific needs and the focus of your template logic.idorlevelIt will help build clearer and more efficient Anqi CMS templates.


Frequently Asked Questions (FAQ)

  1. Q: Can I use parametersidandlevelto get user group information? Answer:No.userGroupDetaillabel'sidandlevelThe parameters are mutually exclusive, you can only select one in a single tag call to specify the user group.

  2. Question: If I passlevelDoes the parameter refer to a user group, but later the background modified the level name of this user group, will the template be affected? Answer:It will be affected. If the name of the user group level in the background changes, and your template still uses the oldlevelIf the value is queried, the tag will not be able to find the matching user group, resulting in the information not being displayed normally. In comparison,idParameters are usually the unique and unchanging identifiers of user groups within the system, therefore when usingidthey are referenced, even if the name of the level changes, as long as the ID remains the same, the label will still work normally.

  3. Ask: Where can I view the user groups in the Anqi CMS backend?idandlevel? Answer:You can find this information in the 'User Group Management' or related 'Member Settings' module on the AnQi CMS backend.Generally, the user group list will display its ID and name, and the detailed editing page of the user group will include configuration items for its level (Level).