将字符串放入阵列Shopify Liquid
在Shopify中,有具有多个数字的元场产品。这些数字代表了产品内鱼类的捕鱼区。 例如,对于产品A,值只是“ 27”,对于产品B,值为“ 27/48”。我要走的方法是创建一个数组,并在此数组中放入值。 这样的事情: 如果Metafield包含27个,则将“大西洋”放在阵列内。如果Metafield包含48个,则将“太平洋”放在阵列内。最后,我会打印出数组。 这是一个好方法还是更好的方法? 谢谢
In shopify there are products with metafields, which contain multiple numbers. These numbers represent the fishing zones of the fish that is inside the product.
For example, for product A the value is simply '27' and for product B the value is '27/48'. My way to go would be to create an array and put in values inside of this array.
Something like this:
If the metafield contains 27, then put 'Atlantic Ocean' inside of the array. If the metafield contains 48, then put 'Pacific Ocean' inside of the array. At the end I would print out the array.
Is this a good way to go or is there a better one?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我只是假设在Metafield中保存“大西洋”等,因为阵列不是您的选择。 这就是我要处理的方式:
所有定义的全局元场
因此,
创建
一个包含
。一种新型的海洋,无需更新液体源代码。
I'm just assuming that saving "Atlantic Ocean" etc. in the Metafield as an array is not an option for you. So here's how I would approach this:
Create a global metafield that contains all definitions like so:
Then, in liquid:
This would render for product A:
And for product B:
This way you can easily update the definition JSON when you want to add a new type of ocean without updating the liquid source code.