In AnQiCMS, flexible content permission control is a key factor in achieving differentiated operations, content monetization, and improving user experience.If you wish to display different content for different user groups, such as 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.
Understand the core content permission of AnQiCMS
One of the core strengths of AnQiCMS 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 applicable to the fine-grained division of backend administrator permissions, but also extends to the display control of front-end content, 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, as well as 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 group and VIP level settings
First, you need to start establishing or improving your user group and VIP level system in the AnQiCMS backend management system.
Define user groups and VIP levels:In the background, under the 'User Management' or related modules, you will find the entry for user groups or VIP level settings.Here, you can create multiple user groups, such as 'General Visitor', 'Registered Member', 'Junior VIP', 'Senior VIP', and so on.Assign a clear name to each user group and assign a numeric "level" identifier. For example:
- General Visitor: Level 0
- Registered member: Level 1
- Primary VIP: Level 2
- Senior VIP: Level 3
These levels are usually increasing, and the higher the level, the theoretically greater the content access permissions. Ensure that these levels are set clearly for easy content matching in the future.
Manage user and level association:After the user registers, the system can automatically assign them to a user group (such as "Registered Member").For VIP users, you can manually allocate from the background, or combine with AnQiCMS's paid content feature to automatically upgrade to the corresponding VIP user group after the user purchases the VIP service.
Assign a 'reading level' attribute to the content
After completing the construction of your user system, the next step is to set the corresponding access barriers for the content on the website.
When you publish or edit articles, products, or any other 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:
- A free news article can be set to 'ReadLevel' 0 (visible to all visitors).
- A deep industry report may need to be set to 'ReadLevel' 2 (visible only to初级VIP and above).
- A VIP exclusive 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.In this way, each piece of content has a clear access threshold.
Implement content display logic in the front-end template.
Real permission control occurs in the website's front-end template. AnQiCMS' powerful template tag system allows you to easily write logic to determine if the current user's level meets the reading requirements of the content.
The following is an example of logic to control content display permissions on a document detail page (for examplearchive/detail.html) as an example:
Assuming you have already been able to obtain the user group level of the currently logged-in user (for example throughuserDetailTag to retrieve userGroupIdand then throughuserGroupDetailGet theGroupIdofLevel), and the content data of the current page (archive) has been loaded.
”`twig {# Assume the archive variable is in the current context, containing all information about the current document #} {% set requiredLevel = archive.ReadLevel %} {# Get the required reading level of the current document #}
{# Assuming you have obtained the actual level of the currently logged-in user, for example, assigned to currentUserLevel #} {# If the user is not logged in or the level cannot be obtained, it is usually set to the lowest level (such as 0), indicating ordinary visitor privileges #} {% set currentUserLevel = 0 %} {# Set to 0 by default, to be updated later according to the actual user situation #}
{# Assume you have a variable to determine if the user is logged in, such as 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 content required level #} {% if currentUserLevel >= requiredLevel %}
{# 用户等级满足要求,显示完整内容 #}
<div class="content-full">
{% archiveDetail with name="Content" %} {# 显示文档的完整内容 #}
</div>
{% else %}
{# 用户等级不足,显示提示信息