Add Section to Shopify theme programmatically
I have a Shopify app and would like to add it to Shopify as dynamic section programmatically. I know how to do it manually.
Basically i create .liquid file in sections in theme code editor. Here is short tutorial for adding dynamic sections: https://www.shopify.com/partners/blog/how-to-create-your-first-shopify-theme-section (https://www.shopify.com/partners/blog/how-to-create-your-first-shopify-theme-section)
But i would like to achieve the same result programmatically, i.e via some API call.
Is it possible at all?
Yes it is possible, but the related API is in preview mode still and is not advised to be used in production environments.
Caution During the preview phase we will be making changes to the sections API based on your feedback. This may cause invalid theme code or page data to be present in preview shops. As the API is iterated upon, we will clean up existing data and theme code on beta-flagged preview shops, which may result in data loss. Changes will be communicated and documentation will be updated.
During the preview phase, the theme editor may not function properly on section-enabled pages.
That being said, have a look at Section Theme Rest API (https://help.shopify.com/en/api/reference/online-store/section-themes). Specifically, you will need to work with Sections Property (https://help.shopify.com/en/api/reference/online-store/section-themes#the-sections-property).
Liquid is a server side rendering language, this means you can not re-render on realtime. but you could render your code and hide it with display: none; and using axios or ajax after calling your API show that section.
Didn't find the answer?
Our community is visited by hundreds of Shopify development professionals every day. Ask your question and get a quick answer for free.
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.