Is modifying the rel canonical in theme.liquid a viable solution to limit duplicate product pages?

I’m trying to limit the number of duplicate product pages and maintain functional breadcrumbs.

To keep the breadcrumbs, I’m using the collection page products. All of my internal links point to:

/collection/collection name/products/product name

I also added /products/* as disallow to robot.txt

Do I need to modify the rel canonical in theme.liquid from the default?

Default is:

{%- if canonical_url != blank -%}

{%- endif -%}

Would something like this work?

{% if template contains ‘collection’ %}

{% else %} {% endif %}

My site is https://beautifulbystorm.com

I’ve made these changes and everything seems to be working well. Let me know if what I’ve done is a viable solution or if I should go about this in another way?

Yeah, that didn’t work… just a little off… for any looking to get this done… this is the code I used and it is working.

{% if template contains ‘product’ %}

{% else %} {% endif %}