_.template

❗️Note this is an alternative implementation. Native template literals not escape html.

Create a template function.

  1. // Lodash/Underscore
  2. const compiled = _.template('hello <%= user %>!');
  3. var result = compiled({ 'user': 'fred' });
  4. console.log(result);
  5. // output: 'hello fred'
  6.  
  7. // Native
  8. const templateLiteral = (value) => `hello ${value.user}`;
  9. var result = templateLiteral({ 'user': 'fred' });
  10. console.log(result);
  11. // output: 'hello fred'

Browser Support for String (template) literals

ChromeEdgeFirefoxIEOperaSafari
41.0 ✔12.0 ✔34.0 ✔28.0 ✔9.0 ✔