-
Notifications
You must be signed in to change notification settings - Fork 0
Usage
Mark Birbeck edited this page Jul 31, 2014
·
1 revision
To use the adapter, invoke the package with the name of the template language you want to use. For example, to use Jade do the following:
var adapter = require('adapter-template');
var jade = adapter('jade');The adapter will now provide access to an appropriate templating engine for Jade. The key interface is a renderFile() method which takes as parameters:
- a path to a template;
- an object that can be used by that template;
- and a callback.
Typical usage would look like this:
jade.renderFile('./test/fixtures/user.jade', { user: 'tobi' }, function (err, html){
console.log(html);
});Since the renderFile() method is in the correct format for Express, to use the adapter in Express we only need to do the following:
var express = require('express');
var adapter = require('adapter-template');
var engineName = 'jade';
var app = express();
app.engine(engineName, adapter(engineName).renderFile);
app.set('views', __dirname + '/fixtures');
...