How do I create pages accessible to specific tagged customers?

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 %}

AT

Hi @hd_zkf ,

May I suggest code below:

{% 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 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 %}

Hi @Huptech-Web , I’ve added in the code but i’m still able to see the content of the page above the restricted members message:

Hi @hd_zkf , Can you please your storefront URL so I can check it once?

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 %}

Is this correct?

Hi,

Could you share a screenshot tag that you added?

All tags must be lowercase.

Ex: “platinum” → work but “Platinum” → not work

to fix this case you can update all tags to lowercase or use code below:

{% assign showContent = true %}
      {% assign customerTags = customer.tags | downcase  %} 
     
      {%  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 customerTags contains 'restrictpagetest' %}
      	  {% assign showContent = true %}
      	{%  endif %}
      {%  endif %}
      {%  if request.page_type == 'page' and page.handle == 'platinum-member' %}
      	{% assign showContent = false %} 
      	{% if customerTags contains 'platinum' %}
      	  {% assign showContent = true %}
      	{%  endif %}
      {%  endif %}
      {%  if request.page_type == 'page' and page.handle == 'gold-member' %}
      	{% assign showContent = false %} 
      	{% if customerTags contains 'gold' %}
      	  {% assign showContent = true %}
      	{%  endif %}
      {%  endif %}
      {%  if request.page_type == 'page' and page.handle == 'silver-member' %}
      	{% assign showContent = false %} 
      	{% if customerTags contains 'silver' %}
      	  {% assign showContent = true %}
      	{%  endif %}
      {%  endif %}
      {%  if request.page_type == 'page' and page.handle == 'bronze-member' %}
      	{% assign showContent = false %} 
      	{% if customerTags 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 %}

Ah yes the tags are in uppercase.

Thank you so much, it works!