How does AnQiCMS control the display or hide of paid content based on user group permissions?

Calendar 👁️ 73

In today's content is king era, how to effectively manage and monetize high-quality content is a focus of many website operators.It is particularly important to precisely control the content access permissions of different users for websites that provide membership services, paid courses, or exclusive information.AnQiCMS as an efficient and customizable content management system provides flexible user group management and VIP system, which can help us easily implement the display or hiding of paid content, thereby better managing content distribution and revenue management.

Understand the user group and permission management of AnQiCMS in depth

One of the core strengths of AnQiCMS is its powerful user group management function.The system allows us to create different user groups and define unique permission levels for each group.This is not just for managing the background operation permissions, but also for fine-grained control over the access to the front-end content.By dividing users into different levels such as ordinary users, VIP users, gold members, etc., we can determine what content they can see and how the content is presented based on the privileges of these user groups.

The built-in VIP system is the key to controlling paid content.It means we can set certain specific content to be 'paid' or 'exclusive member' to access, and it can be linked with the predefined user group level.When a user tries to access this content, the system will decide whether to display the content directly, show a partial preview, or prompt the user to upgrade or purchase based on the user group they belong to and the permission rules set.

Tightly associate content with user group permissions

To implement the display or hide of paid content in AnQiCMS, you first need to associate the content with user group permissions. This is mainly reflected in the content publishing and editing stages.

When we publish or edit a document, in addition to filling in the title, content, categories, tags, and other conventional information, AnQiCMS also provides the document reading level ofReadLevel)or by using custom fields to implement more flexible permission settings.

  1. Using the built-in "Reading Level":If the system has a built-in "Reading Level" feature, we can set a minimum reading level for each document.For example, the reading level of a common article may be 0, an advanced tutorial may require VIP level 1, and an industry report may require level 2 of gold member.Users must reach or exceed this level to access the full content.
  2. To extend permissions through custom fields:AnQiCMS's flexible content model allows us to add custom fields for specific content models (such as articles, products). We can utilize this feature to create such asis_paid_content(Boolean value, indicating whether it is a paid content) orrequired_vip_level(Number, indicating the required VIP level) orallowed_user_groups(Multiple selection, associated with the user group ID that is allowed to access) and other fields. These custom fields provide unlimited possibilities for the refinement of content permission control.

Once the content is marked as requiring specific permissions to access, the next step is how to dynamically display or hide this content on the website front end based on the actual permissions of the user.

Implementation of front-end template: Dynamic display and hide

AnQiCMS uses the Django template engine syntax, providing rich template tags and filters, making it intuitive and powerful to implement frontend permission control. We can combine witharchiveDetail(Document detail tag),userDetail(User detail tag) anduserGroupDetail(User group detail tag),配合ifLogical judgment tag, to build content display logic.

We take a common scenario as an example: when a user is not logged in or does not have enough level, they can only see the summary of paid content and upgrade prompts; while a user who is logged in and has enough level can see the full content.

Assuming we are on the document detail page, and the document has a custom field namedrequired_vip_levelwhich represents the minimum membership level required to access this content.

{# 假设我们正在文档详情页,已获取当前文档详情 archive #}
{% archiveDetail currentArchive with name="all" %} {# 获取当前文档的所有详情 #}
{% userDetail currentUser with name="all" %}       {# 获取当前登录用户的所有信息 #}

{% set contentTitle = currentArchive.Title %}
{% set contentDescription = currentArchive.Description %}
{% set fullContent = currentArchive.Content | safe %} {# 完整内容,注意使用 |safe 过滤器避免HTML转义 #}

{# 从自定义字段中获取访问该内容所需的最低VIP等级。
   这里假设自定义字段名为 'required_vip_level',且值为整数。
   如果字段不存在,可以设置一个默认值,例如0,表示无限制。 #}
{% set requiredLevel = 0 %}
{% archiveParams customParams with id=currentArchive.Id sorted=false %}
    {% if customParams.required_vip_level.Value %}
        {% set requiredLevel = customParams.required_vip_level.Value | integer %}
    {% endif %}
{% endarchiveParams %}

{% set currentUserLevel = 0 %} {# 默认未登录用户等级为0 #}

{% if currentUser.Id %} {# 判断用户是否已登录 #}
    {% userGroupDetail userGroup with id=currentUser.GroupId %} {# 获取当前用户的用户组信息 #}
    {% set currentUserLevel = userGroup.Level %} {# 获取当前用户组的等级 #}
{% endif %}

{# 开始判断内容显示逻辑 #}
{% if currentUserLevel >= requiredLevel %}
    {# 当前用户等级满足或超过所需等级,显示完整内容 #}
    <h1 class="content-title">{{ contentTitle }}</h1>
    <div class="content-description">{{ contentDescription }}</div>
    <div class="full-content-body">
        {{ fullContent }}
    </div>
{% else %}
    {# 用户等级不足或未登录,显示预览和提示 #}
    <h1 class="content-title">{{ contentTitle }} (会员专属)</h1>
    <div class="content-description">
        {{ contentDescription | truncatechars:200 | safe }} {# 显示部分描述作为预览,并确保安全输出 #}
        <p class="preview-more">...</p>
    </div>
    <div class="membership-prompt">
        {% if currentUser.Id %}
            <p>您当前的会员等级是 <strong>{{ currentUserLevel }}</strong>,此内容需要 <strong>{{ requiredLevel }}</strong> 级会员才能查看完整版。</p>
            <p>
                <a href="/member-upgrade" class="btn btn-primary">立即升级会员</a>
                <a href="/member-center" class="btn btn-secondary">前往会员中心</a>
            </p>
        {% else %}
            <p>此为会员专属内容,请登录后查看,或升级至 <strong>{{ requiredLevel }}</strong> 级会员。</p>
            <p>
                <a href="/login" class="btn btn-primary">登录</a>
                <a href="/register" class="btn btn-secondary">注册会员</a>
            </p>
        {% endif %}
    </div>
{% endif %}

In this template code, we first retrieve all the information of the current document as well as the detailed data of the currently logged-in user.Next, we extracted the minimum access level required from the custom fields of the document.By comparing the current user level with the required level, we use{% if %}/{% else %}The structure implements dynamic content display: if the level is sufficient, the full content is displayed; otherwise, a brief preview of the content is displayed, and corresponding prompts and operation entries (such as login, registration, or upgrading to a member) are provided based on the user's login status.

Content operation strategy and advanced application

This ability of AnQiCMS brings great flexibility to content operation:

  • Tiered membership system:We can set different levels of membership (such as ordinary members, silver members, gold members), each level corresponds to exclusive content that can be accessed.
  • Free trial and paid unlock: For high-quality paid content, you can offer a free preview to attract users to pay for the full version.
  • Content bundle sales:Package a series of themed content, set as exclusive for a certain advanced user group, and sell it in the form of a content package.
  • Limited time free/trial:Combine marketing activities, temporarily reduce the access level of some content, or open limited-time free access to specific user groups.

By customizing the content model, we can even refine permission control to a specific field under a specific model.For example, for a 'Product Details' model, we can set the 'Product Price' to be hidden from a specific user group, so only wholesale user groups can see the wholesale price.

In summary, AnQiCMS provides a comprehensive paid content control solution from content publishing to frontend display through its完善 user group management and flexible template tag system.This not only enhances the commercial value of the website content, but also brings users a more personalized and richer browsing experience.


Frequently Asked Questions (FAQ)

  1. Question: If my content is not setrequired_vip_levelCustom fields, orReadLevelIs 0, how will it display?Answer: If the content has not set any permission level, or the level is 0 (usually representing open to all users), then in the above template logic,requiredLevelThe default value will be 0. Since all userscurrentUserLevelAt least 0 (unlogged users can also be considered as level 0), so all users will be able to see the full content.This means that AnQiCMS default content is public, and content will be restricted from access only when the reading level is explicitly set.

  2. What should be done to guide unlogged-in users to register or log in when they visit paid content?In the above template example, whencurrentUser.IdDoes not exist (i.e., the user is not logged in) andrequiredLevelWhen greater than 0, it will display a specific prompt message, including 'login' and 'register member'

Related articles

How to use AnQiCMS's `archiveFilters` tag to dynamically display multi-dimensional content filtering conditions?

How to help visitors quickly find the information they are interested in on a content-rich website is the key to improving user experience and website efficiency.The traditional fixed category navigation often fails to meet users' multi-dimensional and personalized filtering needs.At this time, the `archiveFilters` tag provided by AnQiCMS can fully display its capabilities, helping us dynamically display multi-dimensional content filtering conditions, making your website content management and presentation more flexible and intelligent.

2025-11-09

How to automatically render Markdown format content to HTML when AnQiCMS displays article content?

In Anqi CMS, automatically rendering Markdown content into HTML is a core feature provided by the system, aiming to help content creators publish rich text content in a concise and efficient manner.This process is not a mysterious black box operation, but is achieved through clear settings and flexible template tags.

2025-11-09

How to configure AnQiCMS so that it displays correctly as an independent mobile site on mobile devices?

In AnQiCMS, to provide a better user experience for mobile device users, we can configure the website to display independent site content on mobile devices.This independent operation model for PC and mobile terminals not only helps to design and optimize for different devices in a refined manner, but also can improve the SEO performance of mobile terminals in specific scenarios.AnQiCMS provides us with a variety of website display modes, including the "PC+Mobile independent site" mode, which is the basis for realizing independent content display on the mobile end.Next, we will step by step discuss how to configure AnQiCMS

2025-11-09

How does AnQiCMS dynamically generate and display breadcrumb navigation and control whether to include the current page title?

When building a user-friendly website, breadcrumb navigation plays an indispensable role.It not only can intuitively display the user's current position on the website, avoid getting lost, but also optimize the website structure, which is very beneficial for search engine optimization (SEO).For users of AnQiCMS, utilizing its powerful template tag system to dynamically generate and flexibly control breadcrumb navigation is the key to improving the website experience.

2025-11-09

How to display the 'Previous' and 'Next' document links and titles of the current article in AnQiCMS template?

The effective organization and convenient navigation of website content is the key to improving user experience and extending visit duration.When a visitor is immersed in your article, if they can seamlessly jump to related or adjacent content, it will undoubtedly greatly enhance the continuity of their browsing.AnQiCMS as a fully functional content management system provides intuitive and powerful template tags, helping us easily implement the display of 'Previous' and 'Next' document links and titles on article detail pages.

2025-11-09

How to call and display the subcategory list or associated article list under a specified category in AnQiCMS?

When using AnQiCMS for website content management, we often need to display information according to a specific content organization method.How can you flexibly call and display the list of subcategories under a specified category, or the list of articles associated with that category, which is a scenario many users will encounter.AnQiCMS's powerful template engine and rich tag functions make it intuitive and efficient to meet these requirements.

2025-11-09

How to integrate and display the custom contact information on the AnQiCMS frontend page, such as WhatsApp links?

On AnQiCMS, we often need to allow visitors to contact us in the most convenient way, and WhatsApp, due to its widespread usage, has become the preferred contact tool for many businesses and individuals.Luckyly, AnQiCMS was designed with flexibility in content and functionality in mind, allowing you to easily customize the contact information in the backend and display it on the front page of the website.This article will thoroughly introduce you to how to add and manage custom contact methods like WhatsApp in the AnQiCMS background

2025-11-09

Does the AnQiCMS 'Full Site Content Replacement' feature affect the display of frontend content immediately?

In content operations, sometimes we need to make unified adjustments to a large amount of content on the website, whether it is updating expired information, correcting brand names, or optimizing internal links, manual individual modification is undoubtedly a huge workload.AnQiCMS provides a powerful feature named 'Full Site Content Replacement', aimed at helping us efficiently solve such problems.However, many users may have a question when using this feature: Will the content on the website's front-end be immediately synchronized and updated after the full-site content replacement operation, so that visitors can see the latest modifications?

2025-11-09