![]() |
VOOZH | about |
Underscore.js_.template() function is used to compile JavaScript templates into functions that can be evaluated for rendering. Useful for rendering complicated bits of HTML from JSON data sources. Template functions to create a template function that is compiled and can interpolate properties of data in interpolating delimiters, execute JavaScript in evaluating delimiters, and HTML-escape interpolated properties of data in escape delimiters. Moreover, data properties are retrieved in the template as free variables.
_.template(templateString, [settings]);This method returns the compiled template function.
Example 1: This example shows the use of the _.template() function.
Output:
Hi Shubham!Example 2: This example shows the use of the _.template() function by passing template literal and the object.
Output:
hey Shubham...Example 3: This example shows the use of the _.template() function and passing this function into the foreach loop.
Output:
<li><b>Shubham</b></li><li><b>Shakya</b></li>