从两个单独的循环附加数据

发布于 2025-01-25 15:03:05 字数 851 浏览 2 评论 0原文

第一次在这里发布,如果不是发布此问题的地方,则很抱歉。

也许今天我已经在计算机上了太久了,但是当我试图找出适当的控制流程时,我正在开发一个主题上遇到麻烦。我正在努力获取产品尺寸选项和各个数量可以在前端显示,我希望它显示如下:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

妞丶爷亲个 2025-02-01 15:03:05

尝试这样的事情,如果不正确,它应该非常接近。

{% for i in (1..product.options_by_name['Size'].values.size) %}
  <p>
    {{ product.options_by_name['Size'].values[i] }}
    {{ product.variants[i].inventory_quantity }}
  </p>
{% endfor %}

这是对大小的引用 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.

{% for i in (1..product.options_by_name['Size'].values.size) %}
  <p>
    {{ product.options_by_name['Size'].values[i] }}
    {{ product.variants[i].inventory_quantity }}
  </p>
{% endfor %}

Here are the references to size https://shopify.github.io/liquid/filters/size/ and for loop https://shopify.github.io/liquid/tags/iteration/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文