Today, providing customized experiences for users of different types has become the key to improving user satisfaction and business efficiency.For businesses that have a distribution system, how to ensure that distributors can easily access their exclusive content without causing interference to ordinary users is a common need.AnQiCMS with its flexible template engine and powerful user management features, can help you easily achieve this goal.
Today, let's delve into how to dynamically display content exclusive to distributors in the AnQiCMS template, based on the user'sIsRetailerstatus.
UnderstandingIsRetailerStatus: Your distributor identity identifier
In the AnQiCMS user management system,IsRetailerIt is a very practical user attribute. It is essentially a boolean value (true or false) used to clearly identify whether a user has the identity of a distributor.After you set the distributor role for a user in the background, thisIsRetailerthe status will be activated.
The meaning of this state is that it provides a direct basis for content filtering and display in the front-end template.We can imagine, some content, such as internal training materials, preferential distribution prices, exclusive marketing tool downloads, and so on, are intended to be opened only to distributors.By using the template function of AnQiCMS, we can skillfully make use ofIsRetailerStatus, seamlessly present these contents to distributors while hiding them from other users.
Core logic in the template: conditional judgment and user detail tags
The template engine of AnQiCMS is designed to be very intuitive, it borrows the syntax of Django templates, making conditional judgments simple to perform. The core idea of dynamically displaying exclusive content for distributors is to first obtain the current user'sIsRetailerStatus, then make a conditional judgment based on this status to determine which content should be displayed.
Here, we need to use a very important tag in the AnQiCMS template——userDetail. This tag allows us to retrieve the detailed information of the currently logged-in user. Specifically, we can do it like thisIsRetailerStatus:
{% userDetail isRetailerStatus with name="IsRetailer" %}
This line of code will set the current user'sIsRetailerStatus (a boolean value,trueorfalseAssign to a variable namedisRetailerStatus. Next, we can useifLabel, 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 %}
In this way, you can insert this logic anywhere on the page to achieve fine-grained content control.
Useful scenario: exclusive content display for distributors.
Let us go through several specific examples to see how to utilizeIsRetailerstatus。“
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 for the product in the content model, such asRetailerPriceFor storing the distributor 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 distributor logs in, they will automatically see the exclusive price, while ordinary users will see the market price.
Scenario two: Hidden exclusive download link in article or page
If your website provides some materials exclusively for distributors to download, such as promotional brochures, high-quality image materials, etc., you can wrap these download links in conditional judgments within 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>
This way, only users withIsRetailerstatus can view and download these files.