theme-tools icon indicating copy to clipboard operation
theme-tools copied to clipboard

Add check to prevent overriding any of the global objects

Open macournoyer opened this issue 4 years ago • 2 comments

Bad:

{% assign article = ... %}
{% assign product = ... %}
{% assign collection = ... %}

etc. All the global objects in https://shopify.dev/docs/themes/liquid/reference/objects

We should not flag for product in ....

macournoyer avatar May 03 '21 13:05 macournoyer

Although I agree with this, I believe it shouldn't be a flat no. I use assigns like this within block forloops. For example:

{% for block in section.blocks %}
  {%- assign product = all_products[block.settings.product] -%}
  
  {{ product.title }}
{% endfor %}

This allows for much more native coding within specific areas. In general templates then such a rule should absolutely be enforced, many an hour have I spent diagnosing why product details aren't rendering only to find some dirty app has re-assigned it.

ConduciveMammal avatar May 05 '21 16:05 ConduciveMammal

Ah make sense in this case! Maybe just disallow it a the root instead?

macournoyer avatar May 05 '21 16:05 macournoyer

closing as wont fix

mgmanzella avatar Oct 17 '24 19:10 mgmanzella