Last active
June 6, 2018 01:53
-
-
Save clineamb/86514c5f7c555d0334af to your computer and use it in GitHub Desktop.
[DEPRECIATED] Nunjucks 1.0.7 + Express 4.9.2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Nunjucks + Express | |
* I couldn't find anything that helped me setup the enviornment | |
* correctly for these in the latest vesion of Express 4 (at the time | |
* of writing this). | |
* | |
* This Gist for those that want to keep using Nunjucks with Express 4. | |
* This also goes over working with a Nunjucks environment to use custom | |
* filters, extensions, etc. | |
* | |
* You view files should have ".nunjucks" as the extension. | |
* | |
* - Caroline, 9/18/2014 | |
* | |
*/ | |
var express = require('express'); | |
var nunjucks = require('nunjucks'); | |
var app = express(); | |
// view engine setup | |
app.set('views', path.join(__dirname, 'views')); | |
var env = nunjucks.configure(app.get('views'), { | |
autoescape: true, | |
express: app | |
}); | |
// Example filter setup - remote link assets | |
env.addFilter('asset', function(assetpath) { | |
var asset_url = "/path/to/assets"; // can be a path, or an absolute web URL | |
return asset_url + assetpath; | |
}); | |
app.set('view engine', 'nunjucks'); | |
// Express App setup as per usual. |
var env = nunjucks.configure(app.get('views'), {
autoescape: false, //if passing React components during render
express: app
});
It's the same with Webstorm 9.0.1 - had to download older extention (139.58), but turned out to work great after installation! :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Good snippet! I also use this two lines to change the extension of the templates files.
Thx!