Skip to content
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

Custom Nunjucks environment w/ autoescape #7

Closed
pdehaan opened this issue Jan 30, 2020 · 5 comments
Closed

Custom Nunjucks environment w/ autoescape #7

pdehaan opened this issue Jan 30, 2020 · 5 comments

Comments

@pdehaan
Copy link
Owner

pdehaan commented Jan 30, 2020

Per 11ty/eleventy#495 (comment),

Looks like instead of possibly using the | safe filter on 90% of the output, we might be able to fiddle with autoescape (but requires a custom Nunjucks environment):

  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);

See:

@pdehaan
Copy link
Owner Author

pdehaan commented Jan 31, 2020

Done. See https://github.com/pdehaan/11ty-nunjucks-config

Also filed 11ty/eleventy#895 since this was trickier than expected.

@pdehaan pdehaan closed this as completed Jan 31, 2020
@einomi
Copy link

einomi commented Apr 18, 2021

Done. See https://github.com/pdehaan/11ty-nunjucks-config

Also filed 11ty/eleventy#895 since this was trickier than expected.

@pdehaan when I add a config as in https://github.com/pdehaan/11ty-nunjucks-config, 11ty stops compiling .njk files on change

@pdehaan
Copy link
Owner Author

pdehaan commented Apr 19, 2021

@einomi are you saying the custom nunchucks environment works, but the eleventy —watch behavior breaks?

@einomi
Copy link

einomi commented Apr 19, 2021

@pdehaan yeah, it looks like it doesn't recompile the .njk files when I edit them. However, browsersync reloads the page but the content is not updated on it.

@pdehaan
Copy link
Owner Author

pdehaan commented Apr 19, 2021

@einomi Interesting, if that's still happening in latest 0.12.1 (i think my sample repo above had an older version of Eleventy), I'd file a bug at https://github.com/11ty/eleventy/issues.

In the meantime, you could see if a custom watch target for your nunjucks template folder works: https://www.11ty.dev/docs/watch-serve/#add-your-own-watch-targets

I generally don't use --watch and just rebuild manually, so I'm not very knowledgeable on all things related to watching and rebuilding.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants