从两个单独的循环附加数据
第一次在这里发布,如果不是发布此问题的地方,则很抱歉。
也许今天我已经在计算机上了太久了,但是当我试图找出适当的控制流程时,我正在开发一个主题上遇到麻烦。我正在努力获取产品尺寸选项和各个数量可以在前端显示,我希望它显示如下:
size(QTY)大小(QTY)尺寸(QTY)等...
当前这是什么我在页面的模板文件中有此数据呈现的页面中,
<div class="flex flex-row gap-1">
<p>Size (qty)</p>
{% for value in product.options_by_name['Size'].values %}
<p>{{ value }}</p>
{% endfor %}
{% for variant in product.variants %}
<p>({{ variant.inventory_quantity }})</p>
{% endfor %}
</div>
这将导致以下内容:
size(qty)sml xl(0)(0)(0)(0)(0)(0)
,但理想情况下它将是:
size( size) QTY)s(0)m(0)l(0)xl(0)
这是错误的方法,但是我觉得我应该拥有嵌套在产品选项值循环内部的变体库存数量的逻辑。但是,当我尝试此过程时,循环循环结果只会附加一堆重复的数据,旁边的大小选项旁边的大小选项。
我确定答案可能很明显,但是由于某种原因,我只是没有看到它。任何帮助或建议将不胜感激。
first time posting here so apologies if this isn't the place to post this question.
maybe i've been on the computer too long today but i'm having trouble with a theme i'm developing as i'm trying to figure out the appropriate control flow. i'm working on getting product sizing options and the respective quantities available to display on the front end, and i want it to show as follows:
Size (qty) Size (qty) Size (qty) etc...
currently this is what i have in my template file for the page where this data is being rendered
<div class="flex flex-row gap-1">
<p>Size (qty)</p>
{% for value in product.options_by_name['Size'].values %}
<p>{{ value }}</p>
{% endfor %}
{% for variant in product.variants %}
<p>({{ variant.inventory_quantity }})</p>
{% endfor %}
</div>
this results in an ouput of this:
Size (qty) S M L XL (0) (0) (0) (0)
but ideally it'd be:
Size (qty) S (0) M (0) L (0) XL (0)
perhaps this is the wrong approach, but i feel like i should have the logic for the variant inventory quantity nested inside of the product options values loop. however, when i've tried this the parent for loop just results appends a bunch of duplicate data next to the size options on the front end.
i'm sure the answer to this is probably very obvious but for some reason i'm just not seeing it. any help or advisement would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试这样的事情,如果不正确,它应该非常接近。
这是对大小的引用 https://shopify.github.io/liquid/liquid/filters/filters/size /和for loop https://shopify.github.io/liquid/tags /迭代/
Try something like this, if not correct it should be pretty close.
Here are the references to size https://shopify.github.io/liquid/filters/size/ and for loop https://shopify.github.io/liquid/tags/iteration/