Closed
Description
Hi.
In Liquidjs v9 I have the following code to create custom tags:
engine.registerTag('upper', {
parse: function(tagToken, remainTokens) {
this.str = tagToken.args;
},
render: async function(ctx) {
const str = await this.liquid.evalValue(this.str, ctx);
return str.toUpperCase();
}
});
This code fails in Liquid 10: Uncaught RenderError: Cannot read properties of undefined (reading 'toUpperCase')
.
I found this example in the documentation but it doesn't work either:
engine.registerTag('upper', {
parse: function(tagToken) {
this.str = tagToken.args; // name
},
render: function*(ctx) {
const str = yield this.liquid.evalValue(this.str, ctx);
return str.toUpperCase()
}
});
Activity
fix: support `Context` as `evalValue` parameter, #568
chore(release): 10.3.1 [skip ci]
harttle commentedon Dec 12, 2022
I didn't realize
evalValue
is advocated in docs and demos. I removed support forContext
as second parameter when dealing with #527 because it's not used my source code. Now added it back because I think it's indeed convenient (so I used it in my docs).Performance-wise, it's better to create
new Value()
duringparse
, and callvalue.value()
inrender()
. As in the implementation of builtin tags.oscarotero commentedon Dec 12, 2022
Thanks for the fast response.
I don't have any preference, so if it's more perfomant this suggestion, I'll change it. Can you provide an example for that (or update the example in the documentation)? Somethig like this:
github-actions commentedon Dec 13, 2022
🎉 This issue has been resolved in version 10.3.2 🎉
The release is available on:
Your semantic-release bot 📦🚀
harttle commentedon Dec 13, 2022
Updated this tutorial: https://liquidjs.com/tutorials/sync-and-async.html as well. Hope it helps!
oscarotero commentedon Dec 13, 2022
Perfect. Thanks!
docs: update docs and demo for `Value` usage, fixes harttle#568