在shopify液体页面中编辑JSON数据 [英] Editing JSON data from within a shopify liquid page
问题描述
对于Shopify和液体图书馆来说,这是新手,我有一个客户,他需要一些产品页面来进行定制.一个产品集合产品页面看起来与另一个产品页面相似.
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.
我的计划是简单地打开/关闭显示不需要的元素的JSON设置.
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"
我怎样才能从液体页面中访问该JSON对象?另外,这是进行此操作的最佳方法吗?
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.
推荐答案
product.liquid在脚本的结尾处有此脚本-
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:
- 通过管理面板/应用为特定产品分配其他产品液体模板,并相应地设计模板
- 为每个产品使用特定的产品属性/字段,以区别于其他产品,并在页面加载时将其存储在 JS或液体 变量中;可以用于您的 on/off 逻辑.
- 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.
这篇关于在shopify液体页面中编辑JSON数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!