如何解决将产品变量 Shopify 传递给代码段
设置
我有一家以 Debut 为主题的 Shopify 商店。
在主题的 product-card-grid.liquid
文件中,我调整/添加了以下代码以在集合网格中为每个产品卡添加额外的行,
<div class="h4 grid-view-item__title product-card__title" aria-hidden="true">{{ product.title }}</div>
{% include 'product-price' incl. BTW,variant: product.selected_or_first_available_variant,product: product,show_vendor: show_vendor %}
{%- if product.price > 10000 and product.price < 25000 -%}
<font size = "2">Of renteloos 3x <strong>{{ product.price | divided_by:3 | money_without_trailing_zeros }}</strong></font>
{%- elsif product.price > 25000 -%}
<font size = "2">Of gespreid vanaf <strong>{{ product.price | times: 0.03287 | money_without_trailing_zeros }}</strong> p/m</font>
{%- endif -%}
效果很好。
问题
如果我创建看起来像这样的代码段 own-collection-grid-spreadpayment.liquid
,
{%- if product.price > 10000 and product.price < 25000 -%}
<font size = "2">Of renteloos 3x <strong>{{ product.price | divided_by:3 | money_without_trailing_zeros }}</strong></font>
{%- elsif product.price > 25000 -%}
<font size = "2">Of gespreid vanaf <strong>{{ product.price | times: 0.03287 | money_without_trailing_zeros }}</strong> p/m</font>
{%- endif -%}
然后尝试像这样在 product-card-grid.liquid
中呈现代码片段,
<div class="h4 grid-view-item__title product-card__title" aria-hidden="true">{{ product.title }}</div>
{% include 'product-price' incl. BTW,show_vendor: show_vendor %}
{%- render 'own-collection-grid-spreadpayment' -%}
不显示每个产品的额外行。
尝试
我知道变量应该像这样传递给一个片段,
{%- assign my_variable:'product' -%}
{%- render 'own-collection-grid-spreadpayment',my_variable:my_variable -%}
但仍然没有显示每个产品的额外行。
要么是我做错了上述操作,要么是因为 product
变量本身很特殊或其他什么东西。
问题
我该怎么办,
- 将
product
变量正确传递给代码片段,并且; - 如何正确呈现带有
product
变量的代码段?
解决方法
你的代码有一些我以前从未见过的东西是 incl. BTW
无论如何,这是shopify theme-tags
用 =
而非 :
分配变量,
您将 string
传递给 my_variable
,而不是 object
,当然它不会保存产品数据。
{% assign my_variable = product %}
{% render 'own-collection-grid-spreadpayment' with my_variable %}
或
{% render 'own-collection-grid-spreadpayment' with product,a: a,b: b %}
own-collection-grid-spreadpayment.liquid
{% assign product = own-collection-grid-spreadpayment %}
{%- if product.price > 10000 and product.price < 25000 -%}
<font size = "2">Of renteloos 3x <strong>{{ product.price | divided_by:3 | money_without_trailing_zeros }}</strong></font>
{%- elsif product.price > 25000 -%}
<font size = "2">Of gespreid vanaf <strong>{{ product.price | times: 0.03287 | money_without_trailing_zeros }}</strong> p/m</font>
{%- endif -%}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。