Skip to content

Instantly share code, notes, and snippets.

@obrien-k
Created May 13, 2020 16:08
Show Gist options
  • Save obrien-k/dfcd990755b337db13606e47fd0bd1c8 to your computer and use it in GitHub Desktop.
Save obrien-k/dfcd990755b337db13606e47fd0bd1c8 to your computer and use it in GitHub Desktop.
{{~inject 'template' template}}
{{inject 'token' settings.storefront_api.token}}
<!-- Declare an empty Array as arr
Then iterate over the custom fields for the intended name ('foo' here)
Inject into the current context -->
<script>
let jsContext = JSON.parse({{jsContext}});
let arr = [];
{{#forEach product.custom_fields}}
{{#if name '===' 'foo'}}
{{inject 'productIds' value }}
// Now within the iteration, we want to push to the previously created Array
arr.push({{value}})
{{/if}}
{{/forEach}}
</script>
<!-- Close out the forEach, but we're not done with this data yet, note the injected 'token' and 'arr'-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment