8

Underscore.js does not have a compile function like ejs and jade, but does work as a Node.js module. Would someone please provide an example of how to make it work inside an Express app?

2 Answers 2

20
var _ = require('underscore');

app.register('.html', {
  compile: function (str, options) {
    var template = _.template(str);
    return function (locals) {
      return template(locals);
    };
  }
});
Sign up to request clarification or add additional context in comments.

1 Comment

Note: This is for express <3
4

Now with express 3.0 , it's a bit different. Easy solution : https://github.com/haraldrudell/uinexpress

npm install uinexpress

then

app.configure(function () {
app.engine('html', require('uinexpress').__express)
app.set('view engine', 'html')

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.