If product is in a specific collection, show specific code on page

So I am working on a product specifications table for our website and I would like for the code to show certain aspects of that table based off an if else or case statement.

For example, we have various appliances and instead of having to make a product template for refrigerators, microwaves, ranges, etc. I would prefer if we could have just one template that shows only certain data depending on which collection the product is in.

Something like:

if collection title == refrigerators,

else if collection title == dishwashers,

and so on.

Hi @x2namill ,

Yes, you can use collection title for convenience, or if it’s safer you should use collection handle. Refer https://shopify.dev/api/liquid/objects/collection#collection-handle

Ex code:

{% if collection.handle == 'refrigerators' %}

{% elsif collection.handle == 'dishwashers' %}

{% endif %}

Hope it helps!

When I insert that, I still only see the refrigerator table on the dishwasher page. I’m using the handle I see when I go to collections and click SEO for that specific collection. Is that the correct one to use?

Hi @x2namill ,

Please send your site and if your site is password protected, please send me the password. I will check it.

Hi @x2namill ,

You want to check the condition at product page, if so you need to declare more collection for it because by default collection object will not be able to work at product page.

Please change code:

{% if product.collections[0].handle == 'refrigerators' %}

{% elsif product.collections[0].handle == 'dishwashers' %}

{% endif %}

Hope it helps!

@LitExtension I just implemented that and it’s still not working. The specs table is inside a snippet, is that why it’s not working?

The collection handles are theme-test-refrigerators-freezers and theme-test-dishwashers that I’m trying to use