skip to Main Content

I set a value in settings_data.json of Shopify Config.

And I am trying to insert it into my CSS.

settings_schema.json
...
{
  "type": "image",
  "id": "image1.png"
  "label": "Background Image"
}
...
index.liquid
...
<style>
.div {
 background-color: url({{image1.png}});
}
</style>

But I can’t get the background image.

How can I fix?

2

Answers


  1. You have to use a filter for the image in order to show the full URL address:

    For example: {{ image1.png | img_url: 'medium' }}

    Login or Signup to reply.
  2. To get a value of the store settings you need to call the settings object. Also in your schema it seems that the id contains the value and a comma is missing. Double check this.

    settings_schema.json
    ...
    {
      "type": "image",
      "id": "image1", // Name of variable
      "label": "Background Image",
      "default": "image1.png" // Content
    }
    ...
    index.liquid
    ...
    <style>
    .div {
     background-color: url({{ settings.image1 }});
    }
    </style>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search