-
Hello, I am working on a project where i need to expose CollectionDrop as collections and it is working just fine like: collections["handle"] for a particular collection but at the same time i also need to use collections global which has all collections in it. but i cannot pass two "collections" in data object. I tried adding a default method on CollectionDrop but then the liquidMethodMissing stops working. So i was wondering if there is a way to use the liquidMethodMissing without passing any key like "collections" to avoid conflict between liquidMethodMissing and global? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Create a runkit snippet for your case: https://runkit.com/embed/2is7di4mc7kk The trick is use const {Liquid, Drop} = require('liquidjs')
class CollestionDrop extends Drop {
liquidMethodMissing(key) {
return [key, key.toUpperCase()]
}
valueOf() {
return ["default", "collection"]
}
}
const context = {
collection: new CollestionDrop()
}
const engine = new Liquid()
const template = `
collection: {{collection | join: ","}}
collection.foo: {{collection.foo | join: "," }}"`
engine.parseAndRender(template, context) And here's the newly created doc for Drops: https://liquidjs.com/tutorials/drops.html |
Beta Was this translation helpful? Give feedback.
Create a runkit snippet for your case: https://runkit.com/embed/2is7di4mc7kk The trick is use
toValue()
And here's the newly created doc for Drops: https://liquidjs.com/tutorials/drops.html