Lodash exposes two public properties directly on _: the library version, and the default template delimiters used by template.
_.VERSION
string — the semantic version number of the loaded build.
js
_.VERSION;
// => '4.18.1'_.templateSettings
Object — the default template delimiters used by _.template, styled like embedded Ruby (ERB) and ES2015 template strings. Change these settings to use alternative delimiters across every template call that doesn't pass its own options.
See Security before using
_.template. It executes compiled template strings as JavaScript and the project advises against using it with untrusted input.| Property | Type | Description |
|---|---|---|
_.templateSettings.escape | RegExp | Detects data property values to HTML-escape. |
_.templateSettings.evaluate | RegExp | Detects code to be evaluated. |
_.templateSettings.imports | Object | Variables imported into the compiled template as free variables. Includes imports._, a reference to the lodash function itself, so templates can call Lodash methods directly. |
_.templateSettings.interpolate | RegExp | Detects data property values to inject. |
_.templateSettings.variable | string | The name used to reference the data object inside the template. |
js
// Use custom template delimiters for every template compiled after this line.
_.templateSettings.interpolate = /{{([\s\S]+?)}}/g;
var compiled = _.template('hello {{ user }}!');
compiled({ user: 'mustache' });
// => 'hello mustache!'Lodash reads _.templateSettings when you call template, not when the compiled function runs.
If a change doesn't seem to take effect, see Changing template settings doesn't affect an already-compiled template.
Next steps
- Full
_.templatesignature and options: String methods. _.templatesecurity guidance: Security.