Open noelforte opened 1 week ago
Sorry, I’m a little confused—isn’t this already implemented with https://github.com/noelforte/eleventy-plugin-vento/blob/6590ff60fcb81ef9ebd60dc5eb26ed87a7c1be5d/VentoPlugin.js#L97-L102 ?
Ah, I think I see what you’re asking—you just want a less brittle way of doing it—right? I think we can accommodate that
Yessir, if possible! Or at the very least an "official" recommendation on approach if you have one; even if that's "DIY, you're on your own" 😅
Looks like you do some call()
s on the internal Liquid/Nunjucks engines to populate this
correctly. If bind()
/call()
is the preferred recommendation to plugin authors for wiring up custom engines for adding page
and eleventy
context, that's totally fine for me to support on my end, just say the word and I'll stick with that.
Related https://github.com/11ty/eleventy/issues/3355 let me know if that could be improved, I’m not super happy with it though it is less brittle than DIY
@zachleat first off thank you for offering your time to address this upstream. Here's some observations I've made after several hours of trying, failing, and finally succeeding in using augmentFunctionContext
but I'm not sure if my solution was how you intended for the augmentor method to be used:
As you saw, I loop through all filters per template compiled and add context to each, I'm not sure whether there's a more efficient way to do it, but there it is. My first attempt was calling augmentFunctionContext
with each filter, and then assigning that to Vento's filters
object before compiling the template.
Regardless, that didn't work because this.page
and this.eleventy
were still left unpopulated; this
containing the data cascade and the Vento engine env.
What did end up working for me was supplying data
as the source
option for the augmentor within the filter loop.
Again, I have no idea if this was how you imagined this method being used, and it's more than likely I'm missing something critical here. I reviewed the example you provided for Nunjucks and had trouble seeing how I would apply it to my use case. Only if you have the time, I'm curious to hear if where I arrived was what you envisioned.
Given the API differences from engine to engine in core, and that the implementation for shortcodes/filters differs with core vs plugins maybe it is simpler to just have custom engines handle this
props DIY. The only downside I see being a scenerio where Eleventy introduces, changes, or deletes props on this
for use in filters/shortcodes in the future and then it's up to plugin authors to re-establish feature parity. Not a huge problem since there's only 2 data keys on this
for now. Parity and maintenence are why I brought this
up to begin with.
Sorry for the lengthy response, hope it helps identify any improvements that could be made!
With the addition of https://github.com/11ty/eleventy/issues/3310, it should now be possible to fully integrate Eleventy's template features (filters, shortcodes, paired shortcodes) into this plugin.
Only outstanding thing that still needs to be worked out is the appropriate way to add page context (
this.page
/this.eleventy
) correctly. The approach in https://github.com/11ty/eleventy/issues/3081#issuecomment-2171831699 could work by extending theTemplateEngine
class, or perhaps by doing some other sort of wheel-reinvention to achieve context availability in shortcodes, filters, etc.