Liquid, JavaScript, themes, sales channels
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.
User | RANK |
---|---|
37 | |
28 | |
14 | |
13 | |
9 |
Make the shift from discounts to donations, and witness your business not only thrive fina...
By Holly Dec 4, 2023On our Shopify Expert Marketplace, you can find many trusted third party developers and fr...
By Arno Nov 27, 2023You've downloaded the Search & Discovery app from the Shopify App store, and as you're ...
By Skye Nov 8, 2023