PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, June 30, 2022

[FIXED] How to access custom JSON file in shopify at liquid file level

 June 30, 2022     json, liquid, shopify     No comments   

Issue

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 }}


Solution

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.



Answered By - David Lazar
Answer Checked By - Katrina (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing