-
Notifications
You must be signed in to change notification settings - Fork 23
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
add query options for nunjucks.configure #1
Comments
@Ertle hey man, at the moment I'm not putting much work into this but if you have a change you'd like to submit you are welcome to. The LOC on this is pretty small. |
@Ertle I might have some time to invest in the future. For now we'd happily accept a PR containing the missing features. |
Hey guys, thanks for the nice work on this loader. I was needing to include some custom data from json file to be able to use it in nunjucks templates. |
I created a local patch for this issue that seems to be working for me. This is what the loader looks like set up. /* Nunjucks loader */
const nunjucksOptions = {
configure: function(env){
markdown.register(env, marked);
},
searchPaths: basePath + '/src/html',
context: {
config: {
'env': 'development',
'image_src': '../../assets/images/'
}
}
};
config.module
.rule('nunjucks')
.test(/\.(njk|nunjucks)$/)
.use('html-loader')
.loader('html-loader')
.end()
.use('nunjucks-html-loader')
.loader('nunjucks-html-loader')
.options(nunjucksOptions); I added two lines into index.js to support this. This will probably fault with a type error if you skip the configuration option. So it's probably best to enclose the nunjucksConfiguration function in an if typeof statement. module.exports = function(content) {
this.cacheable();
var callback = this.async();
var opt = utils.parseQuery(this.query);
var nunjucksSearchPaths = opt.searchPaths;
var nunjucksContext = opt.context;
var nunjucksConfiguration = opt.configure;
var loader = new NunjucksLoader(nunjucksSearchPaths, function(path) {
this.addDependency(path);
}.bind(this));
var nunjEnv = new nunjucks.Environment(loader);
nunjucks.configure(null, { watch: false });
nunjucksConfiguration(nunjEnv);
var template = nunjucks.compile(content, nunjEnv);
html = template.render(nunjucksContext);
callback(null, html);
}; |
need a bit more config options, such as autoescape, trimBlocks, tags
https://mozilla.github.io/nunjucks/api.html#configure
The text was updated successfully, but these errors were encountered: