Solved

Want to add class name using collection url

SK08
Shopify Partner
12 0 3

Hi, i want to add a class using collection url and i am using this but both condition is not working.

 

{% if collection.url == '/collections/all/?sort_by=created-descending' %}
New
{% endif %}


{% if page.url == '/collections/all/?sort_by=created-descending' %}
your stuff here
{% endif %}

Accepted Solution (1)

Laura-Hirtop
Shopify Partner
24 5 6

This is an accepted solution.

Hello,

 

Try to replace the conditional with this: 

 

{%- capture contentForQuerystring -%}{{ content_for_header }}{%- endcapture -%}
{%- assign pageUrl = contentForQuerystring | split:'"pageurl":"' | last | split:'"' | first | split:'.com' | lastreplace:'\/','/'replace:'%20',' ' | replace:'\u0026','&'-%}
 
{% if pageUrl contains "?sort_by=created-descending" %}
    -----your stuff here----
{% endif %}
 
I hope it works!

View solution in original post

Replies 2 (2)

Laura-Hirtop
Shopify Partner
24 5 6

This is an accepted solution.

Hello,

 

Try to replace the conditional with this: 

 

{%- capture contentForQuerystring -%}{{ content_for_header }}{%- endcapture -%}
{%- assign pageUrl = contentForQuerystring | split:'"pageurl":"' | last | split:'"' | first | split:'.com' | lastreplace:'\/','/'replace:'%20',' ' | replace:'\u0026','&'-%}
 
{% if pageUrl contains "?sort_by=created-descending" %}
    -----your stuff here----
{% endif %}
 
I hope it works!
SK08
Shopify Partner
12 0 3

@Laura-Hirtop  Thank You It works.