When managing users and content in AnQiCMS, we often encounter the need to display different content based on user identity, such as exclusive articles that only VIP members can watch, or different functional buttons that users of different levels can see. At this point,userGroupDetailTags and the user group levels obtainedLevel) have become the key tools for conditional judgment in our templates.

AnQiCMS is a flexible and efficient content management system, its template engine provides friendly support for Django template syntax, which means we can easily embed logic in the front-end template and dynamically adjust the page based on data.

UnderstandinguserGroupDetailLabel and user group level

First, let's briefly review.userGroupDetailThe role of the label. It is mainly used to obtain detailed information about a user group, including the name, description, purchase price, and what we are focusing on today.User group level (Level)In the AnQiCMS backend, we can set different levels for different user groups, such as level 1 for ordinary users, level 2 for VIP users, and level 3 for senior VIP users, etc.

userGroupDetailWhen tags are used, the user group to be obtained can be specified in two ways:

  • By user group ID (id):If you know the specific ID of the user group, you can specify it directly, for example{% userGroupDetail vipGroup with id="10" %}.
  • By user group level (level):If you are more concerned about a user group of a certain level, you can specify the level directly, for example{% userGroupDetail vipGroup with level="3" %}.

These two methods are either/or, they can both help us get the corresponding user group object, and then access itsLevelfield. Once we have obtained the user group object, for example, by naming itvipGroupThen the level information of the user group can be accessed.{{ vipGroup.Level }}This variable form can be accessed in the template.

Why do we need to make conditional judgments on the user group level?

In the actual operation of AnQiCMS, making conditional judgments on user group levels can help us implement various refined content operation strategies:

  1. Distinguish content access permissions:The most common scenario is to control the visibility of paid content or exclusive content. Only users who reach a certain level can see or access these contents.
  2. Personalized user experience:Based on user level, display different greetings, badges, or exclusive recommendations on the page to enhance the sense of belonging and dignity.
  3. Opening and closing of function modules:Some advanced features or operation buttons may only be open to high-level users, and their display can be flexibly controlled through level judgment.
  4. Guide users to upgrade:For general users, they can be prompted about their current level and the benefits they can obtain by upgrading to a higher level, thereby promoting payment or increasing activity.

The practice of conditional judgment in templates

Now, let's see how to use specific template code examples in AnQiCMS.userGroupDetail