Skip to content

Rendering partials from a .json file #658

Closed Answered by jg-rp
AsadCSE asked this question in Q&A
Discussion options

You must be logged in to vote

This example uses the default FS implementation to find .json templates, and handles JSON parsing and partial settings in a custom {% render %} tag, which extends and falls back to the default render tag.

The plan was to use an instance of Loader from fs/loader.ts for .json template lookup, but LiquidJS does not export it. If this kind of thing works for you, you'll need to either ask @harttle to export Loader (and maybe LookupType) or implement a loader-like class yourself.

import { Liquid, RenderTag, Context } from "liquidjs";

// NOTE: I wanted to use `Loader` from `fs/loader.js`, but it is not exported by LiquidJS.
// This mock loader is incomplete and is just for demonstration purposes.

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by AsadCSE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants