interpolate
1.6

interpolate(object[, pattern]) -> string

Treats the string as a Template and fills it with object’s properties.

Equivalent to calling evaluate on a previously-instantiated Template.

Examples


"#{animals} on a #{transport}".interpolate({ animals: "Pigs", transport: "Surfboard" });
//-> "Pigs on a Surfboard"

var syntax = /(^|.|\r|\n)(\<%=\s*(\w+)\s*%\>)/; //matches symbols like '<%= field %>'
var html = '<div>Name: <b><%= name %></b>, Age: <b><%=age%></b></div>';
html.evaluate({ name: 'John Smith', age: 26 }, syntax);
// -> <div>Name: <b>John Smith</b>, Age: <b>26</b></div>