Lodash _.template() Method Last Updated : 20 Oct, 2023 Comments Improve Suggest changes Like Article Like Report Lodash _.template() method is used to create a template function that is compiled and can interpolate properties of data in interpolate delimiters, execute JavaScript in evaluate delimiters, and HTML-escape interpolated properties of data in escape delimiters. Moreover, data properties are retrieved in the template as free variables. Syntax:_.template([string=''], [options={}]);Parameters: string: It is a string that would be used as the template. It is an optional value.options: It is an object that can be used to modify the behavior of the method. It is an optional value.options.interpolate: It is a regular expression that specifies the HTML interpolate delimiter.options.evaluate: It is a regular expression that specifies the HTML evaluate delimiter.options.escape: It is a regular expression that specifies the HTML escape delimiter.options.imports: It is an object which is to be imported as free variables into the template.options.sourceURL: It is a string that denotes the source URL of the compiled template.options.variable: It is a string that denotes the variable name of the data object.Return Value: This method returns the compiled template function. Example 1: In this example, we are passing a string into the _.template() method. JavaScript // Requiring lodash library const _ = require('lodash'); // Using the _.template() method to // create a compiled template using // the "interpolate" delimiter let comptempl = _.template('Hi <%= author%>!'); // Assigning the value to the // interpolate delimiter let result = comptempl({ 'author': 'Nidhi' }); // Displays output console.log(result); Output: Hi Nidhi!Example 2: In this example, we are passing a string into the _.template() method. and printing the 'geek' into the console. JavaScript // Requiring lodash library const _ = require('lodash'); // Using the _.template() method to // create a compiled template using // the internal print function in // the "evaluate" delimiter let comptempl = _.template( '<% print("hey " + geek); %>...' ); // Assigning value to the evaluate delimiter let result = comptempl({ 'geek': 'Nisha' }); // Displays output console.log(result); Output: hey Nisha...Example 3: In this example, we are passing a string into the _.template() method. The forEach() method is used as the evaluate delimiter in order to generate HTML as output. JavaScript // Requiring lodash library const _ = require("lodash"); // Using the template() method with // additional parameters let compiled_temp = _.template( "<% _.forEach(students, function(students) " + "{ %><li><b><%- students %></b></li><% }); %>" )({ students: ["Rahul", "Rohit"] }); // Displays the output console.log(compiled_temp); Output: <li><b>Rahul</b></li><li><b>Rohit</b></li> Comment More infoAdvertise with us N nidhi1352singh Follow Improve Article Tags : JavaScript Web Technologies JavaScript-Lodash Similar Reads Lodash _.camelCase() Method Lodash _.camelCase() method is used to convert a string into a camel case string. The string can be space-separated, dash-separated, or can be separated by underscores. Syntax:_.camelCase(string);Parameters:string: This parameter holds the string that needs to be converted into a camel case string.R 1 min read Lodash _.capitalize() Method The _.capitalize() method is a part of the Lodash library and is used to format strings. It takes a string as input and returns a new string where the first character is uppercase and all other characters are lowercase. This method is commonly used when formatting user inputs or ensuring consistent 4 min read Lodash _.deburr() Method Lodash _.deburr() method is used to convert Latin-1 Supplement and Latin Extended-A letters to basic Latin letters and removing combining diacritical marks. Syntax:_.deburr([string='']);Parameters: string: This parameter holds the Latin-1 Supplement and Latin Extended-A letters string.Return Value: 1 min read Lodash _.endsWith() Method Lodash _.endsWith() method is used to check whether the string ends with the given target string or not. Syntax:_.endsWith([string=''], [target], [position=string.length]);Parameters: string: This parameter holds the string that needs to be inspected.target: This parameter holds the string that need 1 min read Lodash _.escape() Method Lodash _.escape() method is used to convert the characters "&", "<", ">", '"', and "'" of the given string into their corresponding HTML entities. Syntax:_.escape([string='']);Parameter:string: This parameter holds the string containing escape characters.Return Value: This method returns t 1 min read Lodash _.escapeRegExp() Method Lodash _.escapeRegExp() method is used to escape the Regular Expression special characters "^", "$", "", ".", "*", "+", "?", "(", ")", "[", "]", "{", "}", and "|" in string. Syntax:_.escapeRegExp([string='']);Parameters:string: This parameter holds the string to escape.Return Value:This method retur 1 min read Lodash _.kebabCase() Method Lodash _.kebabCase() method is used to convert the given string into a kebab case string. kebabCase is the practice of writing identifiers using hyphens instead of spaces. The string can be space-separated, dash-separated, or can be separated by underscores. Syntax:_.kebabCase([string='']);Parameter 1 min read Lodash _.lowerCase() Method Lodash _.lowerCase() method is used to convert the given string to lowercase. The string can be space-separated, dash-separated, or can be separated by underscores. Syntax:_.lowerCase([string='']);Parameters:string: This parameter holds the string that needs to be converted into lowercase.Return Val 1 min read Lodash _.lowerFirst() Method Lodash _.lowerFirst() method is used to convert the first character of the given string into lowercase characters. Syntax:_.lowerFirst([string='']);Parameters: string: This parameter holds the string that needs to be converted.Return Value: This method returns the converted string. Example 1: In thi 1 min read Lodash _.pad() Method Lodash_.pad() method is used to pad the string on left and right sides if it is shorter than the given length. If the length can't be divided evenly then padding characters are truncated. Syntax:_.pad([string=''], [length=0], [chars=' '])Parameters: This method accepts three parameters as mentioned 1 min read Like