问题
New to shopify and the liquid library, I have a customer who needs product pages to be a bit custom. One collection of items product page does not look similar to another.
My plan is to simply toggle on/off the JSON settings that display the unwanted elements.
*Pseudocode*
If "product is in collection that doesnt need this element"
" JSON that displays it = false"
How exactly do I access that JSON object from within the liquid pages? Also, is this the best way to go about doing this?
My other thought was to just show/hide the element based on whether its needed.
回答1:
product.liquid has this script at the very end of liquid -
<script>
products.id{{ product.id }} = {{ product | json }};
</script>
Two things you can do here:
- Assign a different product liquid template for particular products through admin panel/app and design the templates accordingly
- Use a specific product property/field for each product to differentiate it from others and store it in a JS or liquid variable when the page loads; which can be used for your on/off logic.
来源:https://stackoverflow.com/questions/33873553/editing-json-data-from-within-a-shopify-liquid-page