Liquid, JavaScript, themes, sales channels
I'm trying to write a loop that will list the properties of an object. Not necessarily the values of the properties, just a list of the properties a particular object has.
Does anyone know how to do that?
It'd be great if there was a consistent way to iterate over an object, but as it stands the most complete information is in the Shopify liquid docs if you're looking at built in objects.
The next best option is to use the "to json" filter. For example:
<!-- Assuming you're in a product liquid template... -->
<script>console.log( {{ product | json }} );</script>
This will give you most object keys (and values). However:
Hope that helps!
Andrew.
Are you ready to take your business to the next level? Look no further than the latest ...
By SarahF_Shopify Apr 15, 2024We’re keeping the ball rolling to make sure you’re always ahead of the game. So buckle ...
By JasonH Apr 8, 2024Portrait of Stephen positioned next to an image of planet Earth, with the Stephen's World ...
By JasonH Mar 18, 2024