How can I use the if function on Json in Dwan Theme Collection Modification?

There is a way to use the if function in the liquid code to achieve a restricted page for specific tagged customers.
But the collection in dawn theme is running on Json.

I tried to implement the collection liquid code template with the if function, the if works fine but the collection content doesn’t display correctly.

So is there a way to use the if function on Json?

Hi @KKK6 ,

The JSON template file only supports JSON code, so you can’t add liquid code. Can you describe more about the code, I will help you to check and add it.

Because with adding code at collection.json file you can add code at main-collection-product-grid.liquid file it will work the same.

Hope it helps!

Thanks for the reply!

The JSON template is the Dawn collection default which looks something like:
{“sections”: {“product-grid”: {
“type”: “main-collection-product-grid”

The following are the liquid code I found for a VIP-tagged customer only collection:
{% if customer.tags contains ‘vip’ %}

{% section ‘collection’ %}

{% else %}

{{ pages.no-access.content }}

{% endif %}

I can’t use liquid in JSON so I tried to use the sample collection liquid code here.
As a result, the if function works perfectly but the collection doesn’t display correctly.

Hi @KKK6 ,

It’s not a collection section. Please go to main-collection-product-grid.liquid file and add code here:

Or simply, you just need to create conditions at theme.liquid file, it will work fine. Refer:

Code:

{%- if request.page_type == 'collection' -%}
        {%- if customer.tags contains 'vip' -%}
          {{ content_for_layout }}
        {%- else -%}
          {{ pages.no-access.content }}
        {%- endif -%}
      {%- else -%}
        {{ content_for_layout }}
      {%- endif -%}

Hope it is clear to you.

Thank you so so much for the detailed explanations!
But if I want to create one or two special collections that are VIP tagged instead of all collection being restricted, what approach I might have?

Oh wait I figured it out!
Thanks! The above method is perfect!

1 Like