-
-
Notifications
You must be signed in to change notification settings - Fork 495
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature request: Expose Nunjucks' addGlobal #495
Comments
Would a syntax like (I believe I implemented something related to that but haven't packaged it up, yet) |
I think that might work but it's sort of arcane syntax. Kind of related to this comment from the nunjucks maintainer that filters are somewhat awkward syntax on top of function calls. |
@robdodson Elventy might not directly support it, but you can add them manually (I discovered this week) by using your own Nunjucks environment. I'm already doing similar to be able to set some specific Nunjucks options. Inside your eleventy.js: let nunjucksEnvironment = new Nunjucks.Environment(
new Nunjucks.FileSystemLoader(["src/site/_templates"]), // we need to pass in our includes dir here
{
lstripBlocks: true,
trimBlocks: true,
autoescape: false
});
nunjucksEnvironment.addGlobal(name, nunjucksGlobals[name]);
eleventyConfig.setLibrary("njk", nunjucksEnvironment); FWIW I've made a similar filter. I'm pleased to see the syntax matches @Ryuno-Ki's suggested. I also accept an optional arg to do exact matching or not. I've also just found out that filters (at least for Nunjucks) have access to the context. So I'm tempted to rework my filter to not require collections at all - just take a slug and return the item / array of items / false. |
|
I was curious if addGlobal might be something eleventy could expose.
In my instance I wanted to call a function that takes two arguments. It doesn't feel like I could do this correctly with a filter. I could use a shortcode to do this, but then I can't pipe the results into a filter.
Essentially I'm trying to do:
The text was updated successfully, but these errors were encountered: