Ad

Basic Shopify - Using An Image From Settings_scheme.json

- 1 answer

I am able to create an option in my theme to upload 2 images. These will be on a carousel as part of a homepage splash.

I have achieved this with the following code in my settings_scheme.json file:

[
  {
    "name": "Homepage Splash",
    "settings": [
      {
        "type": "paragraph",
        "content": "Choose images for homepage splash"
      },
      {
        "type": "image",
        "id": "slideshow_1.jpg",
        "label": "Image 1"
      },
       {
        "type": "image",
        "id": "slideshow_2.jpg",
        "label": "Image 2"
      }
    ]
  }
]

My question is, how do I now access these two images to display them as part of my 'homepage-splash.liquid'? Looking at other templates the code should be something like this:

{% for i in (1..2) %}
<img src='{% capture image %}slideshow_{{ i }}.jpg{% endcapture %}'>
{% endfor %}

But this outputs nothing in html. I'm sure it is something very basic I am missing as I am new to Shopify. Please could someone advise, it will really help me develop further. Thanks, DB

Ad

Answer

Your code should look like this

{% for i in (1..2) %}
    {% capture image %}slideshow_{{ i }}.jpg{% endcapture %}
    <img src="{{ image | asset_url }}"/>
{% endfor %}
Ad
source: stackoverflow.com
Ad