express-dynamic-partials
v0.1.1
Published
render partials server side
Downloads
4
Maintainers
Readme
express-dynamic-partials
Dynamically render partials server-side. Works with any view engine, eg ejs, jade, etc.
Add it as middleware:
var app = express();
var partials = require('express-dynamic-partials');
app.locals.basedir = __dirname + '/partials');
app.use('/render', partials(app.locals.basedir, 'jade'));
Supports any view engine:
app.use('/render', partials(app.locals.basedir, 'ejs'));
If no view engine is specified, it will use the app's view engine:
app.set('view engine', 'ejs');
app.use('/render', partials(app.locals.basedir)); // will use ejs
Create a partial:
/partials
/my-partial.jade
h1= text
Dynamically render the partial:
curl localhost:3000/render/my-partial?text=hello
Returns:
<h1>hello</h1>
Installation
$ npm install express-dynamic-partials
var app = express();
var partials = require('express-dynamic-partials');
app.locals.basedir = __dirname + '/partials');
app.use('/render', partials(app.locals.basedir, 'jade'));