Underscore.JS - template method



Syntax

_.template(templateString, [settings])

template method complies javascript code into functions which can be used to render html. See the below example −

Example

var _ = require('underscore');

var template = _.template("Hello: <%= name %>");
console.log(template({name: 'Sam'}));

Save the above program in tester.js. Run the following command to execute this program.

Command

\>node tester.js

Output

Hello Sam
underscorejs_utilities.htm
Advertisements