簡體   English   中英

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

[英]How to add Image in section in Shopify?

我想在首頁中添加圖片,為此,我在以下部分的customimg.liquid中添加了此代碼

{
"type": "image_picker",
"id": "image_1",
"label": "Image"    
}

模板-> index.liquid

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

該圖像未顯示在主頁上。

在此處輸入圖片說明

您能在我想念的地方幫助我嗎? 謝謝

由於您像這樣調用該部分,所以{% 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: 'master'不使用它。 改用img_url: '2048x'

這是錯誤的{{ settings.image_1 ... 您必須這樣稱呼{{ section.settings.image_1 ...

您無法在該部分之外調用圖片! 您必須在節內調用圖像,因為section對象只能在節內訪問。


您的代碼應如何顯示:

小節/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' %}

或者,您的代碼可以是動態的,如下所示

部分/自定義液體

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

模板/index.liquid

{{ content_for_index }}

動態方式允許您從管理面板中添加部分而不是單個部分。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM