Nervously Proposing Marriage
Have ideas to improve npm?Join in the discussion! »

express-dynamic-partials

0.1.1 • Public • Published

express-dynamic-partials

NPM Version NPM Downloads Node.js Version Build Status Coverage Status Gittip

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

MIT Licensed

Install

npm i express-dynamic-partials

DownloadsWeekly Downloads

5

Version

0.1.1

License

MIT

Last publish

Collaborators

  • avatar