What's your biggest current challenge? Have your say in Community Polls along the right column.
Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

How to apply shopify extension snippet to theme with API

Solved

How to apply shopify extension snippet to theme with API

Petro_P
Shopify Partner
21 4 3

Hi, I am trying to set up a theme app extension,
I created an extension and published it with the snippet.
Now I want to apply this snippet to the store's main theme. But I don't understand how to do it.
Snippet should be added to theme.liquid file. 
I can change theme assets with API to include my code, but I don't understand how to do it with app extensions.

I read this doc, but its unclear https://shopify.dev/docs/apps/online-store/theme-app-extensions/update

 

I need exactly this, but it's unclear how to do it with the app extension

For example, apps often require the following to integrate with online stores:

  • Adding snippets to the snippets directory of a published theme, which are then added to a page by modifying Liquid layout, template, or section files.


How to apply code block or snippet to the theme.

Loyalty and Rewards + Referrals app- Skymars Loyalty
Accepted Solution (1)

Petro_P
Shopify Partner
21 4 3

This is an accepted solution.

OK I found the answer, I need to create block with "target": "body",

Loyalty and Rewards + Referrals app- Skymars Loyalty

View solution in original post

Replies 3 (3)

Petro_P
Shopify Partner
21 4 3

This is an accepted solution.

OK I found the answer, I need to create block with "target": "body",

Loyalty and Rewards + Referrals app- Skymars Loyalty
Skuibida
Shopify Partner
1 0 0

Hey, I wanted to follow up on your recent response regarding the code issue. While I appreciate your input, it would be immensely helpful if you could provide a more detailed explanation of your solution. Could you please expand on the steps and thought process behind your answer, including any relevant code snippets or considerations? This would greatly enhance my understanding and benefit others who may encounter a similar problem.

Petro_P
Shopify Partner
21 4 3

You need to create a block as described in documentation
for example
your-block.liquid

{% schema %}
{
"name": "Block name",
"target": "body",
"javascript": "yourjavascriptfile.js",
"settings": []
}
{% endschema %}

Then you can deploy this with Shopify cli
after that, you need to use a deep link - and ask the customer/to enable your block using that deep link.
https://shopify.dev/docs/apps/online-store/theme-app-extensions/extensions-framework#deep-linking
Loyalty and Rewards + Referrals app- Skymars Loyalty