Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access custom JSON file in shopify at liquid file level

I know it is possible to access a JSON file at the JavaScript level on the front end, but is it possible to access a JSON file and its contents in /assets/ folder (or elsewhere if need be) at the Liquid level?

I was hoping for something like

{{ '/assets/some_file.json.liquid' | example_object.inner_object.some_key }}

like image 841
Andre Bulatov Avatar asked Nov 01 '25 05:11

Andre Bulatov


1 Answers

During server-side rendering, Shopify turns Liquid into a massive string, and sends that across the wire as browser food. HTML, CSS and JS.

If you have an asset foo.js containing JSON, you can indeed render that to the client, as

{{ 'foo.js' | asset_url }}

But you cannot use the JSON itself to steer any kind of server-side rendering. You can embed Liquid tags in your JS file and name it foo.js.liquid, and anything in your Liquid will affect the render, but then why bother with the JSON part?

If you are so interested in special Liquid rendering, setup your theme to render with settings and their values.

Alternatively, once the JSON downloads to the client, you are free to monkey around with pure JS to achieve glory.

like image 145
David Lazar Avatar answered Nov 03 '25 21:11

David Lazar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!