How can I correctly use if/unless statements in code?

Hello, I am having trouble with this if/unless statement. Essentially, I want to render a line item property in the buy button section, only for a specific collection. I have tried different variations of code to try and get it working but nothing seems to work right, any advice would be appreciated.

{% if product.handle == ‘small’ or ‘shopify’%}
{%- unless collection.handle == ‘prebuilt-shopify-stores’ -%}

LINE ITEM CODE

{%- endunless -%}
{% endif %}

I only want the line item code to be rendered when the collection handle is www.mywebsite.com/collections/shopify I have tried {% if collection.handle = ‘shopify’ %} Thanks!

Hi @biznazz101

You code is absolutely fine.

But it will only work when your product url structure will be as provided below.

https://[store url].com/collection/[collection name]/products/[product handle]

Only then liquid code will able to get the product collection details.

I think you should find other way to get the collection detail.

I see that explains why it isn’t working.

How can I render a section based on the collection title?

For example, this does not work:

{% if collection.title == 'Shopify Small Tasks'%}

  
  

Hi @biznazz101

There is no liquid code which could help you in getting collection handle.

Since you just need to add the input field you can use querystring to get the name or handle of collection on product page.

Hope this will help you…