Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
This is related to My other question but I felt it needed to be asked on it's own. As stated above, attempting to fetch data from a collection always fails on the robots.txt.liquid template. Even just trying to fetch the number of products in a collection will not return anything.
collections['discon'].all_products_count
Below is some code I was using while trying to figure out what was going on. Any attempt to loop over the products in the target collection will fail when the code is placed in robots.txt.liquid. If I use that code in any other template it will work perfectly.
{% for product in collections['discon'].products %}
{% if forloop.first %}
{% assign discon = product.handle | append: "," %}
{% else %}
{% assign discon = discon | append: product.handle | append: "," %}
{% assign noindexdiscon = discon | split: "," %}
{% endif %}
{% else %}
{% assign noindexdiscon = "loop, has, failed" | split: ", " %}
{% endfor %}
{%- if group.user_agent.value == '*' -%}
{% for dcprod in noindexdiscon %}
{{ 'Disallow: /' | append: dcprod }}
{% endfor %}
{%- endif -%}
{%- if group.user_agent.value == '*' -%}
{% for product in collections['discon'].products %}
{{ 'Disallow: /collections/test-test-test*' }}
{% assign discon = product.handle %}
{% assign noindexdiscon = 'Disallow: /products/' | append: discon %}
{{ noindexdiscon }}
{% else %}
{{ 'Disallow: /loop-0-length*' }}
{% endfor %}
{%- endif -%}
Anyone know if this is a bug or one of those limitations/restrictions that Shopify can't be bothered to document? Or am I being an idiot and this limitation is listed, but I missed it?
I am trying to automatically add products from a specific collection to the disallow list, as those products have been discontinued. I want them removed from search indexes before I archive the products.
Shopify and our financial partners regularly review and update verification requiremen...
By Jacqui Mar 14, 2025Unlock the potential of marketing on your business growth with Shopify Academy's late...
By Shopify Mar 12, 2025Learn how to increase conversion rates in every stage of the customer journey by enroll...
By Shopify Mar 5, 2025