skip to Main Content

I’m trying to create a link to the app settings within a Shopify block using schema in Liquid. I want to include dynamic variables like shop.domain and block.id in the URL.

Here’s my code:

{% schema %}
{
    "name": "block",
    "target": "body",
    "settings": [
        {
          "type": "header",
          "content": "Customize [App Configuration Page](https://admin.shopify.com/store/{{ shop.domain }}/apps/myapp/{{ block.id }})"
        }
    ]
}
{% endschema %}

However, the variables {{ shop.domain }} and {{ block.id }} are not being parsed within the schema. The link displays as plain text rather than dynamically replacing these variables.

Is there a way to include dynamic variables in the link within the Shopify block schema? If not, are there any recommended workarounds for creating dynamic links in Shopify blocks?

UPDATE 1

Thanks for reply – but this button is visible at front public page …

and i see enter image description here in this app – they create link to app – so shop url is dynamic variable . Hot they do it ?

2

Answers


  1. You can not directly include dynamic variables in URLs within the Shopify schema, you can work around this limitation by using a combination of block settings and Liquid templating outside the schema.

    First, define a block setting for a part of the URL:

    {% schema %}
    {
        "name": "Custom Block",
        "settings": [
            {
                "type": "text",
                "id": "url_part",
                "label": "URL Part",
                "default": "myapp"
            }
        ]
    }
    {% endschema %}
    

    Then,

    {% if block.settings.url_part %}
       <a href="https://admin.shopify.com/store/{{ shop.domain }}/apps/{{ block.settings.url_part }}/{{ block.id }}">App Configuration Page</a>
     {% endif %}
    
    Login or Signup to reply.
  2. You need to use the type liquid in the schema.

        {
          "type": "liquid",
          "id": "d_link",
          "label": "Dynamic Link"
        },
    

    Then in the customizer you can add the liquid code into the block.

    https://admin.shopify.com/store/{{ shop.domain }}/apps/myapp/
    

    And when you get the variable into the code you need to append the block.id.

    {{ block.settings.d_link | append: block.id }}
    

    Then you get the dynamic link like below example:

    https://admin.shopify.com/store/tech-checkout-ex.myshopify.com/apps/myapp/buttons_XF8RPK
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search