【问题标题】:Creating linkable Image with Text in Blocks Shopify在 Blocks Shopify 中创建带有文本的可点击图像
【发布时间】:2021-01-29 09:32:16
【问题描述】:

我试图在 Shopify 部分中创建一个块,一个带有文本的可链接图像 - 它们应该成为我页面的一个新部分,并具有 3 个功能:添加图像、图像链接、标题和描述。它也可以有 2 列。但是,此脚本无法保存。这是它的

  {% for block in section.blocks %}  
  <div class="img" id="call-to-action">   
        <h1> {{ block.settings.text-box-title }} </h1>
        <h3> {{ block.settings.text-box-content }} </h3>
        <a href="{{ image-settings.link }}" class="img img--cta">{{ image.settings.link }}</a>
    </div>
  {% endfor %}


{% schema %}
{
  "name": "CTA Blocks",
  "max_blocks": 3,
   "settings": [
    {
      "id": "text-box",
      "type": "text",
      "label": "Heading",
      "default": "Title"
    }
  ],
  "blocks": [
    {
      "name": "Add Image with Text",
      "settings": [
        {
          "id": "image",
          "type": "image_picker",
            "label": "Image"
        },
        {
          "id": "link",
          "type": "url",
        "label": "Image link"
        },
        {
        "name": "Text Box",
        "settings": [
            {
                "id": "text-box-title",
                "type": "text",
                "label": "Heading",
                "default": "Title"
            },
            {
                "id": "text-box-content",
                "type": "richtext",
                "label": "Add custom text below",
                "default": "<p>Add your text here</p>"
        }
      ]
    }
  ],
  "presets": [
    {
      "name": "Call to Action Blocks",
      "category": "CTA button",
      "blocks": [
        { 
          "type": "select"
        },
        {
          "type": "select"
        }
      ]
    }
  ]
}
{% endschema %}

{% stylesheet %}
{% endstylesheet %}

{% javascript %}
{% endjavascript %}

你能帮帮我吗?谢谢。

【问题讨论】:

    标签: image text shopify block sections


    【解决方案1】:
    【解决方案2】:

    您的 JSON 无效,应该是:

    {
        "name": "CTA Blocks",
        "max_blocks": 3,
        "settings": [{
            "id": "text-box",
            "type": "text",
            "label": "Heading",
            "default": "Title"
        }],
        "blocks": [{
            "name": "Add Image with Text",
            "settings": [{
                    "id": "image",
                    "type": "image_picker",
                    "label": "Image"
                },
                {
                    "id": "link",
                    "type": "url",
                    "label": "Image link"
                },
                {
                    "name": "Text Box",
                    "settings": [{
                            "id": "text-box-title",
                            "type": "text",
                            "label": "Heading",
                            "default": "Title"
                        },
                        {
                            "id": "text-box-content",
                            "type": "richtext",
                            "label": "Add custom text below",
                            "default": "<p>Add your text here</p>"
                        }
                    ]
                }
            ],
            "presets": [{
                "name": "Call to Action Blocks",
                "category": "CTA button",
                "blocks": [{
                        "type": "select"
                    },
                    {
                        "type": "select"
                    }
                ]
            }]
        }]
    }
    

    这是检查 JSON 的好工具: https://jsonlint.com/

    【讨论】:

    • 感谢您的检查,koosa,我真的很感激 :)
    【解决方案3】:

    我已经解决了您的代码问题。所以,请使用下面附加的更新代码。

    {% for block in section.blocks %}  
      <div class="img" id="call-to-action-{{ block.id }}">   
        <h1> {{ block.settings.text-box-title }} </h1>
        <h3> {{ block.settings.text-box-content }} </h3>
        <a href="{{ block.settings.link }}" class="img-link-wrap img--cta">
          <img src="{{ block.settings.image | img_url : '600x600' }}" alt="" >
        </a>
      </div>
    {% endfor %}
    
    
    {% schema %}
    {
        "name": "CTA Blocks",
        "max_blocks": 2,
        "settings": [
          {
            "id": "text-box",
            "type": "text",
            "label": "Heading",
            "default": "Title"
          }
        ],
        "blocks": [
          {
            "type": "image",
            "name": "Add Image with Text",
            "settings": [
                {
                  "id": "image",
                  "type": "image_picker",
                  "label": "Image"
                },
                {
                  "id": "link",
                  "type": "url",
                  "label": "Image link"
                },
                {
                  "id": "text-box-title",
                  "type": "text",
                  "label": "Heading",
                  "default": "Title"
                },
                {
                  "id": "text-box-content",
                  "type": "richtext",
                  "label": "Add custom text below",
                  "default": "<p>Add your text here</p>"
                }
              ]
           }     
        ],
        "presets": [
          {
            "name": "CTA Blocks",
            "category": "CTA button",
            "blocks": [
              { 
                "type": "image"
              }
            ]
          }
        ]
    }
    {% endschema %}
    

    【讨论】:

    • 太棒了!这正是我需要的,非常感谢你,Vr_Mistry :) 有一件事,当我想添加图片时,它一直在底部区域 - 如何将其更改为右侧区域?
    • 感谢您对我的回答,能否请您给我您所需设计的屏幕截图,以便我设置视图。
    • 您好 Vr_Mistry,感谢您的及时回复!我已经在答案部分发布了所需的设计。 i.stack.imgur.com/HwZaq.png - 这是我添加新分区块(或新图像)时脚本的结果i.stack.imgur.com/lprnP.png - 这是添加新分区块(或新图像)时我需要的结果谢谢。
    • 嗨celubba,谢谢你的截图,我会按照你给的截图给你设计。您能分享一下您的 Shopify 商店的链接吗?
    猜你喜欢
    • 1970-01-01
    • 2011-02-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多