Berk
Berk

Reputation: 85

How to restrict page access for non-tagged users

As you can read from the title, I'm really struggling to restrict non-tagged users from a specific page. I currently have a default blog called 'news' and a blog called 'course' for customers who bought a membership from the store. Those customers are getting tagged as 'member'.

In main-blog.liquid I already made an if statement which keeps customers with no 'member' tag outside. This is not so efficient since normal customers are also getting blocked from the default 'news' blog.

My code:

{% if customer.tags contains 'member' %}
 {%- paginate blog.articles by 6 -%}
  <div class="main-blog page-width section-{{ section.id }}-padding">
   <h1 class="title--primary">{{ blog.title | escape }}</h1>

   <div class="blog-articles {% if section.settings.layout == 'collage' %}blog-articles--collage{% endif %}">
   {%- for article in blog.articles -%}
   <div class="blog-articles__article article">
        {%- render 'article-card',
          article: article,
          media_height: section.settings.image_height,
          media_aspect_ratio: article.image.aspect_ratio,
          show_image: section.settings.show_image,
          show_date: section.settings.show_date,
          show_author: section.settings.show_author,
          show_excerpt: true 
        -%}
      </div>
   {%- endfor -%}
   </div>

   {%- if paginate.pages > 1 -%}
    {%- render 'pagination', paginate: paginate -%}
   {%- endif -%}
  </div>
 {%- endpaginate -%}
{% endif %}

How can I code in a way that normal customers can only see the default 'news' blog and the tagged customers see both 'news' and 'course' blogs?

Upvotes: 0

Views: 64

Answers (1)

Alice Girard
Alice Girard

Reputation: 2173

You'll need real blog handles but this should do the work.

{% case blog.handle %}

{% when 'course' %}

    {% if customer.tags contains 'members' %}
        Display blog articles
    {% else %}
        Login, subscribe, etc...
    {% endif %}

{% else %}

    Display blog articles

{% endcase %} 

Upvotes: 1

Related Questions