如何在Shopify的部分添加图像?

时间:2019-02-08 06:58:27

标签: image shopify

我想在首页中添加图片,为此,我将代码添加到customimg.liquid中的

部分下
{
"type": "image_picker",
"id": "image_1",
"label": "Image"    
}

template-> index.liquid

{% section 'customimg' %}
{{ settings.image_1 | img_url: 'master' | img_tag }}

图片未显示在首页上。

enter image description here

您能在我想念的地方帮我吗? 谢谢

1 个答案:

答案 0 :(得分:2)

由于您像这样{% section 'customimg' %}而不是使用{{ content_for_index }}来调用该部分,因此我假设您希望该部分是静态的。

首先,您需要在此处https://help.shopify.com/en/themes/development/sections

中阅读有关如何使用节的大量信息。

与您的代码一起出现

本节中的结构必须这样写:

{% schema %}
{
  "name": "Image",
  "settings": [
    {
      "type": "image_picker",
      "id": "image_1",
      "label": "Image"    
    }
  ]
}
{% endschema %}

已弃用img_url: 'master',请不要使用它。改用img_url: '2048x'

这是错误的{{ settings.image_1 ...。您必须这样称呼{{ section.settings.image_1 ...

您不能在该部分之外调用图像!您必须在该部分内调用该图像,因为section对象只能在该部分内访问。


您的代码应如何显示:

  

sections / customimg.liquid

{{ section.settings.image_1 | img_url: '2048x' | img_tag }}

{% schema %}
{
  "name": "Image",
  "settings": [
    {
      "type": "image_picker",
      "id": "image_1",
      "label": "Image"    
    }
  ]
}
{% endschema %}
  

templates / index.html

{% section 'customimg' %}

作为替代,您的代码可以是动态的,看起来像这样

  

sections / custommg.liquid

{{ section.settings.image_1 | img_url: '2048x' | img_tag }}

{% schema %}
{
  "name": "Image",
  "settings": [
    {
      "type": "image_picker",
      "id": "image_1",
      "label": "Image"    
    }
  ],
  "presets": [
    {
      "name": "Image",
      "category": "Content"
    }
  ]
}
{% endschema %}
  

templates / index.liquid

{{ content_for_index }}

动态方式允许您从管理面板中添加部分的乘数,而不是一个。