dynamic metafield in theme app block

lokki54
Shopify Partner
42 0 9

Hello.

Can someone help to migrate discontinued assets API to the theme app blocks?

 

How to use app.metafields in the theme app block settings? What type of metafield should be (json or list.single_line_text_field)

in the conditional-app-block.liquid I call for metafield but got an error with the Shopify extension push 

 

 

[blocks/conditional-app-block.liquid] Invalid tag 'schema': settings: with id="vertical_alignment" options must be an array

 

 

 

"settings": [
    {
      "type": "header",
      "content": "Dynamic Block?"
    },
    {
      "type": "paragraph",
      "content": "text."
    },
    {
      "type": "select",
      "id": "vertical_alignment",
      "label": "Vertical alignment",
      "options": "[{{ app.metafields.appsomething.some_select }}]"
    }
  ]
}
{% endschema %}

 

 

Replies 2 (2)

EcomGraduates
Shopify Partner
588 48 77

hello there  

 

To migrate discontinued assets API to the theme app blocks, you need to use the app's metafields instead. Here's a general outline of how you can do it:

  1. In your app, create a new metafield for the data you want to migrate. This metafield can be of type "json" or "list.single_line_text_field", depending on the type of data you want to store.

  2. In your app's code, retrieve the data from the discontinued assets API and store it in the new metafield. You can use the Shopify API to retrieve the data and then set the value of the metafield using the "PUT /admin/api/2021-09/metafields/{metafield_id}.json" API endpoint.

  3. In your theme app block settings, use the app's metafield to populate the select options. Here's an example of what the code might look like:

 

 

In this example, the "options" field is populated with the value of the "some_select" metafield from the "appsomething" namespace.

 

lokki54
Shopify Partner
42 0 9

Hello.

But where are the "examples"? You post empty spaces.

Will greatly appreciate for example of code!