Today, with the increasingly rich digital content, providing customized experiences for users of different types has become a key factor in improving user satisfaction and business efficiency.For businesses with a distribution system, ensuring that distributors can easily access their exclusive content without causing interference to ordinary users is a common requirement.AnQiCMS Based on its flexible template engine and powerful user management features, it allows you to easily achieve this goal.

Today, let's delve into how to dynamically display content exclusive to distributors in the AnQiCMS template based on userIsRetailerstatus.

UnderstandingIsRetailerStatus: Your distributor identity tag.

In the user management system of AnQiCMS,IsRetailerIt is a very practical user attribute.It is essentially a boolean value (true or false) used to explicitly indicate whether a user has the identity of a distributor.IsRetailerthe status will be activated.

The meaning of this status is that it provides a direct judgment basis for us to filter and display content in the front-end template.We can imagine that some content, such as internal training materials, exclusive promotional distribution prices, and dedicated marketing tools for download, are intended to be accessible only to distributors.IsRetailerStatus, seamlessly present these contents to distributors while hiding them from other users.

Core logic in the template: conditional judgment and user detail tags

AnQiCMS's template engine is designed to be very intuitive, drawing on the syntax of Django templates to make conditional judgments simple and straightforward. The core idea to dynamically display exclusive content for distributors is to first obtain the current user'sIsRetailerStatus, then make conditional judgments based on this status to determine which content should be displayed.

Here, we need to use a very important tag in the AnQiCMS template—userDetailThis tag allows us to retrieve the detailed information of the currently logged-in user. Specifically, we can get it like this.IsRetailerStatus:

{% userDetail isRetailerStatus with name="IsRetailer" %}

This line of code will set the current user'sIsRetailerstatus (a boolean value,trueorfalse)Assign it to a variable namedisRetailerStatus. Next, we can useiftags, based onisRetailerStatusto control the display of content.

For example, a basic conditional judgment structure might look like this:

{% userDetail isRetailerStatus with name="IsRetailer" %}

{% if isRetailerStatus %}
    {# 这里放置分销员才能看到的内容 #}
    <div class="retailer-exclusive-content">
        <p>欢迎回来,尊敬的分销员!您可以看到这些专属内容。</p>
        <!-- 更多分销员专属信息... -->
    </div>
{% else %}
    {# 这里放置普通用户或未登录用户看到的内容 #}
    <div class="general-content">
        <p>您好!部分内容仅对分销员开放。</p>
        <a href="/register">注册成为分销员</a>,获取更多权益!
    </div>
{% endif %}

Through this method, you can insert this logic at any position on the page, achieving fine-grained content control.

Practical scenario: exclusive content display for distributors

Let's look at several specific examples to see how to use it in practiceIsRetailerstatus.

Scenario one: Displaying different distribution prices on the product page

Assuming your product page needs to display a special purchase price for distributors. You can add a custom field to the content model for the product, such asRetailerPrice,used to store the agent price.

{# 假设您正在产品详情页,archive 变量已包含产品信息 #}
{% userDetail isRetailerStatus with name="IsRetailer" %}

<div class="product-info">
    <h2>{{ archive.Title }}</h2>
    <p>市场零售价: <span>{{ archive.Price }}</span> 元</p>

    {% if isRetailerStatus %}
        <p class="retailer-price">分销员专属价: <span>{{ archive.RetailerPrice }}</span> 元</p>
        <button class="buy-now-retailer">立即采购</button>
    {% else %}
        <p>如果您是我们的分销员,可享受更优惠的采购价格。</p>
        <button class="add-to-cart">加入购物车</button>
    {% endif %}

    <div class="product-description">
        <h3>产品详情</h3>
        {{ archive.Content|safe }}
    </div>
</div>

In this way, after the agent logs in, they will automatically see the exclusive price, while the general user will see the market price.

Scene two: Hidden exclusive download link in article or page

If your website provides some materials for distributors to download, such as promotional brochures, high-quality image materials, etc., you can wrap these download links in conditional statements in articles or single pages.

{# 假设您正在文章详情页 #}
{% userDetail isRetailerStatus with name="IsRetailer" %}

<article>
    <h1>{{ archive.Title }}</h1>
    <div class="article-content">
        {{ archive.Content|safe }}
    </div>

    {% if isRetailerStatus %}
        <div class="download-section retailer-only">
            <h3>分销员专属下载区</h3>
            <p>这里提供最新的产品手册、营销海报源文件等,助您更好地开展业务。</p>
            <ul>
                <li><a href="/files/product-manual-retailer.pdf" download>产品手册(分销版)</a></li>
                <li><a href="/files/marketing-poster-source.zip" download>营销海报源文件</a></li>
            </ul>
        </div>
    {% else %}
        <div class="download-section guest-prompt">
            <p>如需获取更多营销资料,请<a href="/login">登录</a>或<a href="/register">注册</a>成为我们的分销合作伙伴。</p>
        </div>
    {% endif %}
</article>

Thus, only those withIsRetailerstatus can see and download these files.