In AnQiCMS, flexible content permission control is a key factor in achieving differentiated operation, content monetization, and enhancing user experience.If you want to display different content for different user groups, such as ordinary visitors, registered members, or VIP users, AnQiCMS provides a complete user group and VIP level management function, making the refined distribution of content easily accessible.

Understanding AnQiCMS Content Permissions Core

AnQiCMS's one of the core strengths is its powerful 'User Group Management and VIP System'.This feature allows you to group users of the website and define specific permission levels for each group.This mechanism is not only suitable for fine-grained division of backend administrator permissions, but also extends to the control of front-end content display, allowing you to decide what content users can see based on their identity or their VIP level.The ultimate user value lies in the fact that you can easily build paid content, membership services, thereby effectively realizing content monetization and user loyalty management.

The key to implementing content display permission control lies in two core elements: the 'ReadLevel' attribute of the content itself, and the 'Level' associated with the 'User Group' the user belongs to.AnQiCMS is exactly through comparing these two levels to determine whether the content is visible to the current user.

Build Your User System: User Groups and VIP Level Settings

Firstly, you need to start building or perfecting your user groups and VIP levels in the AnQiCMS backend management system.

  1. Define user groups and VIP levels:In the "User Management" or related modules in the background, you will find the entry for user groups or VIP levels.Here, you can create multiple user groups, such as "General VisitorAssign a clear name for each user group and assign a numeric 'level' identifier.

    • Common Visitor: Level 0
    • Registered member: Level 1
    • Junior VIP: Level 2
    • Senior VIP: Level 3

    These levels are usually incremental, and the higher the level, the greater the theoretical content access rights. Ensure that these levels are clearly set to facilitate subsequent content matching.

  2. Manage user and level association:Users registered can be automatically assigned to a user group by default (such as "Registered Member").For VIP users, you can manually assign through the backend or combine with the AnQiCMS paid content feature to automatically upgrade to the corresponding VIP user group after the user purchases the VIP service.

Assign the 'Reading Level' attribute to content

After your user system is set up, the next step is to set the corresponding access barriers for the content on the website.

When you post or edit articles, products, or any content, AnQiCMS allows you to set a property named 'Document Reading Level' (ReadLevel) for each article or product.This 'ReadLevel' is the minimum access permission requirement for the content.

For example:

  • An article of free news copy, which can be set 'ReadLevel' to 0 (visible to all visitors).
  • An in-depth industry report, may need to be set as “ReadLevel” 2 (visible only to VIPs and above).
  • An exclusive VIP product page, can be set to 'ReadLevel' as 3 (visible only to senior VIP users).

This property is usually set in the "Other Parameters" or similar custom field area of the content editing interface.Through this way, each piece of content has a clear access threshold.

Implement content display logic in the front-end template.

The real permission control happens in the website's frontend template.AnQiCMS powerful template tag system, allowing you to easily write logic, judge whether the current user's level meets the reading requirements of the content.

The following is an example of logic for controlling content display permissions on a document detail page (for example,archive/detail.html):

Assuming you have already been able to obtain the user group level of the currently logged-in user (for example, through)userDetailLabel retrieve userGroupIdThen throughuserGroupDetailRetrieve theGroupIdofLevel) And the content data of the current page (archive) Has been loaded.

`twig {# 假设 archive 变量在当前上下文,包含当前文档的所有信息 #} {% set requiredLevel = archive.ReadLevel %} {# 获取当前文档的所需阅读等级 #}

{# 假设您已通过某种方式获取了当前登录用户的实际等级,例如赋值给 currentUserLevel #} {# 如果用户未登录,或者无法获取等级,通常默认设置为最低等级(如0),表示普通访客权限 #} {% set currentUserLevel = 0 %} {# 默认设置为0,稍后根据实际用户情况更新 #}

{# 假设您有判断用户是否登录的变量,例如 isUserLoggedIn #} {% if isUserLoggedIn %}

{# 获取当前登录用户的ID,假设为 currentUserId #}
{% userDetail userProfile with id=currentUserId %}
{# 获取用户所属用户组的详情 #}
{% userGroupDetail userGroup with id=userProfile.GroupId %}
{% set currentUserLevel = userGroup.Level %} {# 获取当前用户的实际等级 #}

{% endif %}

{# Now, compare the user level with the required level #} {% if currentUserLevel >= requiredLevel %}

{# 用户等级满足要求,显示完整内容 #}
<div class="content-full">
    {% archiveDetail with name="Content" %} {# 显示文档的完整内容 #}
</div>

{% else %} English

{# 用户等级不足,显示提示信息