-
env: "liquidjs": "^9.28.0", I feel like this use to work but it has been a lot of time since I checked. const { Liquid, Tokenizer } = require('liquidjs');
const liquid = new Liquid({jsTruthy: true});
let tpl = `{% if blank %} BLANK TRUE {% else %} BLANK FALSE {% endif %}`;
let context = {blank: ''};
(async function() {
let ret = await liquid.parseAndRender(tpl, context);
console.log(ret);
// OUTPUT: BLANK TRUE
})() |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Further investigation. The problem seems to be in the following function: function isFalsy(val, ctx) {
if (ctx.opts.jsTruthy) {
console.log(`JSTRUTHY typeof=${typeof val},val=${JSON.stringify(val)}`);
//OUTPUT: JSTRUTHY typeof=object,val={}
return !val;
}
else {
return val === false || undefined === val || val === null;
}
} When the string is blank, typeof val is an empty object rather than an empty string. So !val evaluates to false. |
Beta Was this translation helpful? Give feedback.
-
Ok... I think i found the problem. The word "blank" as a variable doesn't seem to be valid. It's considered a literalValue. So my test is bad.. if i change blank to blankvar, then it works fine. |
Beta Was this translation helpful? Give feedback.
Ok... I think i found the problem. The word "blank" as a variable doesn't seem to be valid. It's considered a literalValue. So my test is bad.. if i change blank to blankvar, then it works fine.