|
Hi, I have a small issues when using a import { Context, Liquid } from "liquidjs";
const engine = new Liquid({
strictFilters: true,
strictVariables: true,
trimTagLeft: false,
trimTagRight: false,
trimOutputLeft: false,
trimOutputRight: false,
greedy: false,
lenientIf: true,
});
const map = {
s: "a",
};
console.log(await engine.parseAndRender("{{ s }}", map));
try {
console.log(await engine.parseAndRender("({{ x }})", map));
} catch (e) {
console.log("Caught error:", e.message);
}
// So far, so good, without context, undefined variables throw.
const context = new Context({
s: "b",
});
console.log(await engine.parseAndRender("{{ s }}", context));
try {
console.log(
await engine.parseAndRender("({{ y }})", context, {
strictVariables: true,
}),
);
} catch (e) {
console.log("Caught error:", e.message);
}The result I get when running this code is: % node ./index.js
a
Caught error: undefined variable: x, line:1, col:5
b
()I also tried without the second Is there anything else I have to configure to make this work? |
Answered by
jg-rp
Jan 29, 2026
Replies: 1 comment 1 reply
|
Try passing This is roughly what const context = new Context({ s: "b" }, engine.options, { sync: false });liquidjs/src/context/context.ts Line 41 in 02403a1 |
1 reply
Answer selected by
ilg-ul
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Try passing
engine.optionsas the second argument to theContextconstructor.This is roughly what
Liquid.parseAndRenderdoes when creating an implicit context for you.liquidjs/src/context/context.ts
Line 41 in 02403a1