skip to Main Content

My setting_data.json (Deput Shopify Theme)file:

{
  "current": {
    "checkout_error_color": "#ff6d6d",
    "sections": {
      "header": {
        "type": "header",
        "settings": {
          "align_logo": "left",
          "logo": "shopify://shop_images/logo_9bb43dd5-21d6-442c-8a19-0f4adf03e13a.png",
          "logo_max_width": 100,
          "main_linklist": "main-menu",
          "message": true,
          "home_page_only": true,
          "message_text": "Paw Paper – Edible Gift Wrap for Pets",
          "message_link": "",
          "color_bg": "#162950",
          "color_text": "#ffffff"
        }
      },

How I can get section header variables in Shopify liquid template page?

I can get one variable:

{% assign text_color = settings.color_text %}
{{ text_color }}

I need to show custom block on page and get data for it from settings_data.json

"1543393771012": {
        "type": "custom-content",
        "blocks": {
          "1543393771012-1": {
            "type": "image",
            "settings": {
              "image": "shopify://shop_images/info.png",
              "width": "50%",
              "alignment": "center"
            }
          },
          "1543393802354": {
            "type": "html",
            "settings": {
              "code": "<p>Paw Paper is the world's first edible wrapping paper designed specifically for pets. Our edible paper is 100% all-natural, made from potato starch with Omega-3 enhanced beef flavoring. It's water-soluble so no tape required!</p> <p>Just lick it like a stamp or dab water on the edges to bind the seams.</p>",
              "width": "50%"
            }
          }
        },

But, I can not get and display array with variables.

Help, please.

2

Answers


  1. Assuming your JSONOBJ is correct.

    var JSONOBJ={
      "current": {
        "checkout_error_color": "#ff6d6d",
        "sections": {
          "header": {
            "type": "header",
            "settings": {
              "align_logo": "left",
              "logo": "shopify://shop_images/logo_9bb43dd5-21d6-442c-8a19-0f4adf03e13a.png",
              "logo_max_width": 100,
              "main_linklist": "main-menu",
              "message": true,
              "home_page_only": true,
              "message_text": "Paw Paper – Edible Gift Wrap for Pets",
              "message_link": "",
              "color_bg": "#162950",
              "color_text": "#ffffff"
            }
          }}}}
    
    console.log(JSONOBJ.current.sections.header.settings.message_text)
    Login or Signup to reply.
  2. The settings_data.json file isn’t something you can access directly in Liquid – but you can access the values stored within using the appropriate Liquid commands.

    The global settings object in Liquid gives you access to all the variables defined in your settings_schema.json file, and nothing more.

    However, your color_text setting isn’t a theme setting, it’s a section setting for the section named ‘header’. This variable can be accessed as section.settings.color_text, so long as you are calling that from inside your header section.

    Block settings are accessed in a similar way. Assuming that you have some sort of for block in section.blocks loop, those block-level settings can be accessed as block.settings.whatever_key_you_made

    Remember – all of the settings you create have a corresponding scope and need to be accessed appropriately! settings_schema.json gives you your global settings object; each section has its private settings object; and each block has it’s own personal settings object.

    Hope this helps!

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search