【问题标题】:Pass product variable Shopify to snippet将产品变量 Shopify 传递给代码段
【发布时间】:2021-03-25 10:26:37
【问题描述】:

设置

我有一个以 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 -%} 

效果很好。


问题

如果我创建看起来像这样的 sn-p 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中的sn-p,

<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 %}  

{%- render 'own-collection-grid-spreadpayment' -%}        

每个产品的额外行不显示。


尝试

我知道变量应该像这样传递给 sn-p,

{%- assign my_variable:'product' -%}      
{%- render 'own-collection-grid-spreadpayment', my_variable:my_variable  -%}       

但仍然没有显示每个产品的额外行。

要么我做错了,要么与 product 变量本身的特殊性有关。


问题

我该怎么做,

  1. product 变量正确传递给sn-p,并且;
  2. 如何正确渲染带有product 变量的sn-p?

【问题讨论】:

    标签: shopify product render code-snippets assign


    【解决方案1】:

    你的代码有一些我以前从未见过的东西,那就是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 -%}   
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-01-09
      • 2018-03-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多