mozilla / nunjucks

A powerful templating engine with inheritance, asynchronous control, and more (jinja2 inspired)
https://mozilla.github.io/nunjucks/
BSD 2-Clause "Simplified" License
8.48k stars 635 forks source link

Cannot create multiple instances each having its own configuration #1400

Open mustafaekim opened 2 years ago

mustafaekim commented 2 years ago

Hi, is there a way to create multiple instance of nunjucks template engine so that we can have different configurations for each instance?

ogonkov commented 2 years ago

Sure.

mustafaekim commented 2 years ago

Thanks, however it seems like it does not work as expected. Below, I added the first line as per the documentation and commented out the second line, but I am getting the below error.

(node:35524) UnhandledPromiseRejectionWarning: Error: Cannot find module 'njk'

var nunjucksEnv = new LX.nunjucks.Environment(new LX.nunjucks.FileSystemLoader('views'), nunjucksConfig);
//LX.nunjucks.configure('views', nunjucksConfig)

Do you have any idea how to make it work?

PS: LX simply exports the nunjucks from npm.