As mentioned in the title, I’d like to create pages accessible to specific tagged customers. I already have this code to have a specific page accessible for logged-in users, which works:
{%- if customer or canonical_url contains '/account' -%}
{{ content_for_layout }}
{%- else -%}
{%- if canonical_url contains 'pages/members' -%}
<div class="page-width" style="text-align:center">
<h1>Only members can access this page.</h1>
<div class="rte">
<p>Please login or create an account to see this content.</p>
<br>
<div class="login__button">
<a class="button" href="/account/login" style="color: pink;">Log in</a>
</div>
</div>
</div>
{%- else -%}
{{ content_for_layout }}
{%- endif -%}
{%- endif -%}
But I’d like to have another page that’s accessible to tiered members (eg. Bronze, Silver, Gold, Platinum). These tiers will be separated by the respective customer tags. To test this, I’ve tried adding in this code below the code previously mentioned, but it would only ignore the restriction on both pages:
{%- if customer.tags contains 'restrictpagetest' -%}
{{ content_for_layout }}
{%- else -%}
{%- if canonical_url contains 'pages/restrictedpage' -%}
<div class="page-width" style="text-align:center">
<h1>Only restricted members can access this page.</h1>
<div class="rte">
<p>Please login or create an account to see this content.</p>
<br>
<div class="login__button">
<a class="button" href="/account/login" style="color: pink;">Log in</a>
</div>
</div>
</div>
{%- else -%}
{{ content_for_layout }}
{%- endif -%}
{%- endif -%}
Any ideas would be appreciated! I’d like to avoid installing apps as well. Thank you!
Hello @hd_zkf , If you want to create a page accessible for specific tagged customers, please replace the below code with your code for the tagged customers.
{% unless canonical_url contains 'pages/restrictedpage' %}
{{ content_for_layout }}
{% else %}
{% if customer %}
{% if customer.tags contains 'restrictpagetest' %}
{{ content_for_layout }}
{% else %}
You are not allowed to view this page!
{% endif %}
{% else %}
# Only restricted members can access this page.
Please login or create an account to see this content.
Log in
{% endif %}
{% endunless %}
Hi @EBOOST , thanks for this! It works. Just one more question.
I’d like to have different pages to cater to different tags, i.e Bronze, Silver, Gold, Platinum. I tried adding the code like this but it’s still inaccessible for the following tagged customers.
{% assign showContent = true %}
{% if request.page_type == 'page' and page.handle == 'members' %}
{% unless customer %}
{% assign showContent = false %}
{% endunless %}
{% endif %}
{% if request.page_type == 'page' and page.handle == 'restrictedpage' %}
{% assign showContent = false %}
{% if customer.tags contains 'restrictpagetest' %}
{% assign showContent = true %}
{% endif %}
{% endif %}
{% if request.page_type == 'page' and page.handle == 'platinum-member' %}
{% assign showContent = false %}
{% if customer.tags contains 'platinum' %}
{% assign showContent = true %}
{% endif %}
{% endif %}
{% if request.page_type == 'page' and page.handle == 'gold-member' %}
{% assign showContent = false %}
{% if customer.tags contains 'gold' %}
{% assign showContent = true %}
{% endif %}
{% endif %}
{% if request.page_type == 'page' and page.handle == 'silver-member' %}
{% assign showContent = false %}
{% if customer.tags contains 'silver' %}
{% assign showContent = true %}
{% endif %}
{% endif %}
{% if request.page_type == 'page' and page.handle == 'bronze-member' %}
{% assign showContent = false %}
{% if customer.tags contains 'bronze' %}
{% assign showContent = true %}
{% endif %}
{% endif %}
{% if showContent %}
{{ content_for_layout }}
{% else %}
# Only members can access this page.
{% unless customer %}
Please login or create an account to see this content.
Log in
{% endunless %}
{% endif %}