How to create a liquid file in Shopify from the custom app?

Create liquid file is necessary when developer want to create a liquid file for their app. This file could be placed anywhere in your main theme like Layout, Templates, Sections, Snippets, Assets etc. But before we create a new file in it, we have to need some data, so let’s start the code.create a new liquid file from your app Step 1. Foremost, take the access token and shop name in variables. Step 2. Mention the below function at the top line.
require_once("inc/functions.php");
$requests = $_GET;

$hmac = $_GET['hmac'];

$serializeArray = serialize($requests);

$requests = array_diff_key($requests, array('hmac' => ''));

ksort($requests);

$token = "Paste your app Access token";

$shop = "Paste your shop name here;
$requests = $_GET;

$hmac = $_GET['hmac'];

$serializeArray = serialize($requests);

$requests = array_diff_key($requests, array('hmac' => ''));

ksort($requests);

$token = "Paste your app Access token";

$shop = "Paste your shop name here;
$url = parse_url( 'https://' . $shop );
$host = explode('.', $url['host'] );
$shop  = $host[0];

$MyTheme = shopify_call_shop($token, $shop, "/admin/api/2020-04/themes.json", array(), 'GET');
$MyTheme = json_decode($theme['response'], JSON_PRETTY_PRINT);

//  print_r($MyTheme );
Till here if you remove the comment from the above last line than you can see the list of array with your all themes names, their ID and other details. Now we want that theme, which is currently main theme. So let’s go ahead.
$requests = $_GET;

$hmac = $_GET['hmac'];

$serializeArray = serialize($requests);

$requests = array_diff_key($requests, array('hmac' => ''));

ksort($requests);

$token = "Paste your app Access token";

$shop = "Paste your shop name here;
$url = parse_url( 'https://' . $shop );
$host = explode('.', $url['host'] );
$shop  = $host[0];

$MyTheme = shopify_call_shop($token, $shop, "/admin/api/2020-04/themes.json", array(), 'GET');
$MyTheme = json_decode($theme['response'], JSON_PRETTY_PRINT);

//  print_r($MyTheme );

foreach($MyTheme as $live_theme) {
	foreach ($live_theme as $key => $value) {
		if($value['role'] === 'main') {
			$Active_theme =  $value['id']; 
      // echo $Active_theme ;
      $asset_file = array(
				"asset" => array(
									"key" => "sections/filename.liquid",
									"value" => '<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
                  <script src="https://myopt.option.in/Advance_option/js/Advance_option.js"></script>'
								)
			);

			$asset = shopify_call_shop($token, $shop, "/admin/api/2020-04/themes/" . $Active_theme .  "/assets.json", $asset_file, 'PUT');
			$asset = json_decode($asset['response'], JSON_PRETTY_PRINT);

			echo print_r($asset);

		}
	}
}
Now if you run the above code you can see that in your Shopify inside sections you can find a newly generated file called filename .Liquid which we have recently mention above. Similarly, you can set any file name at any folder wherever you want, but you can’t create a new folder you have to keep your liquid file any in existing folder.

How to Limit a number to a minimum value in Shopifyexpoundsofttechsolution How to set UK timezone in javascript?