Open gautam14 opened 7 years ago
Hi @gautam14 You will need to save a copy of the liquid file as a string then insert your code. see this http://stackoverflow.com/questions/30883360/modify-theme-liquid-using-shopify-api
Hi myjanky
Thanks for your response.
I read this post and follow the way it tells --first save a copy of the theme.liquid then used this code
$shopify('PUT /admin/themes/145783113/assets.json', array( 'asset' => array( 'key' => 'layout/theme.liquid', 'value' => "hello"; ) ));
to append the data/value, but the main problem is that when I append my data in theme.liquid it overwrite all the previous data and just append "hello" in file.
Can you please tell how I can append my data after/before the particular data in theme.liquid file.
Thanks!
The value must contain the entire liquid of the theme.liquid file as well as your "Hello" wherever you want it to be at. For example if the contents of theme.liquid are
<head>
<body>My Theme</body>
</head>
You would grab a copy of the theme liquid with the asset API get. Pseudocode...
var current_theme = '<head>
<body>My Theme</body>
</head>'; //possibly from the get asset var.
var new_theme = jQuery(current_theme).find('body').append('Hello');
then pass new_theme in as the value parameter in the put
Hi myjanky,
I have tried the code but getting the desired result.
--my code is:
"<?php $mycustom = $shopify('GET /admin/themes/145783113/assets.json?asset[key]=layout/theme.liquid&theme_id=145783113'); $me = $mycustom['value'];
?>"
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
var current_theme = "<?php echo $me; ?>"; //possibly from the get asset var.
var new_theme = jQuery(current_theme).find('body').append('<h1>Hello</h1>');
//console.log(new_theme);
})
</script>
"<?php //////// code /////////?>"
But "hello" is not appending in code. I just the beginner, can you please tell where I am doing wrong.
Thanks!
I am not sure that JS is correct. Do you have the console errors from console.log? What does the content of $me look like dumped to the console?
Hi myjanky,
I don't know whats going wrong, but no error is showing in console.log. Can you please help me in this, I just want modify theme.liquid using API.
Thanks!
I would not mix PHP and JS for this. I was thinking you would use one or the other.
printr($me);
what is in that?>
Hi, I am building an shopify app using phpish/shopify_app-skeleton, can anyone tell me how to add the snippet in theme.liquid when app is installed in store first time. I used this code
$shopify('PUT /admin/themes/145783113/assets.json', array( 'asset' => array( 'key' => 'layout/theme.liquid', 'value' => "hello"; ) ));
But this code overwrite whole code and just append "hello" . Please help me in adding snippet and content to it.
Thanks