Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Is the order attribute in JSON templates redundant?

Is the order attribute in JSON templates redundant?

rbhsiags
Shopify Partner
4 0 1

The order of sections in a JSON template can be determined simply by the order of properties in the `sections` attribute's value. So, I'm pretty confused about the purpose the `order` attribute.

 

Furthermore, when you reorder sections in a JSON template using the theme editor, the order of the entries in the `sections` attribute are changed to reflect the order of the sections in the theme editor. Hence, it seems like the `order` attribute is completely redundant, since the order of sections can simply be determined by looking at the order of sections in the `sections` attribute.

 

So I'm pretty confused about why JSON templates are designed this way. That is, why wasn't the `sections` attribute designed to be an array, instead of an object?

 

In other words, is there ever a useful case for when the order of sections that appear on the `order` attribute is different than the order of sections that appear on the `sections` attribute? Because it seems like this would be the only scenario where the current design makes sense. Am I missing something here?

Reply 1 (1)

Liam
Community Manager
3108 342 884

Hi Rbhsiags,

 

You're correct in noting that when section arrangement changes are made in the theme editor that both the `sections` attribute and the `order` array is updated. Using the `order` array to arrange the default order can be helpful for theme developers selling themes on marketplaces, as they want to quickly and easily rearrange the order of sections for the default state, without needing to move the JSON objects around. Typically these templates are intended to be set up so that merchants and developers don't need to touch them, and changes can be made either via the theme editor or the respective Liquid section files. 

 

Hope this helps!

Liam | Developer Advocate @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog