How to render snippet file in main theme file through API

anoop-chauhan
New Member
1 0 0

Hi all, I have a question that after creating a snippet file through Shopify API, can we render it in the main theme file through Shopify API?

0 Likes
Kin156
New Member
1 0 0

You can achieve this by the assets in Shopify.

https://shopify.dev/docs/admin-api/rest/reference/online-store/asset#update-2021-04

Please find the below reference link for the detailed explanation by one of the Shopify staff.

https://shopify.dev/docs/admin-api/rest/reference/online-store/asset#update-2021-04

 

Hope that helps.

0 Likes
faisalsaeed15
Shopify Partner
5 1 1

You cannot use asset admin API to get snippet file in main theme.

You can use null layout template for rendering the code via ajax.

We have to create a new alternate template for example: page.dynamic-content.liquid, then in that template file we have to write in start of file:

{% layout none %}

Your liquid code here


then on any page of the theme. you can render this by using ajax request like this

$.ajax({
type: 'get',
url: '/page?view=dynamic-content',
success: function(data){
    $('.element').html(data); // append the returned rendered result into any html element
}
});

 

0 Likes