Editing JSON data from within a shopify liquid page

不羁的心 提交于 2019-12-13 05:20:33

问题


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:

  1. Assign a different product liquid template for particular products through admin panel/app and design the templates accordingly
  2. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!