The default settings object used by _.template() for delimiters (escape, evaluate, interpolate), free-variable imports, and the data variable name. Part of Lodash Properties (stable in 4.x — not deprecated). Warning:_.template compiles executable code — never use untrusted template strings; Lodash plans to remove it in v5.
Remember
_.templateSettings
// Defaults used by _.template(string, [options])
// options on _.template() override these values
escape // RegExp → <%- value %> (HTML-escaped)
interpolate // RegExp → <%= value %> (raw insert)
evaluate // RegExp → <% code %> (run JS)
imports // Object of free variables (includes _)
variable // data object name (optional)
save = _.templateSettings.interpolate
_.templateSettings.interpolate = /{{([\s\S]+?)}}/g
compiled = _.template('hello {{ user }}!')
compiled({ user: 'mustache' })
→ "hello mustache!"
_.templateSettings.interpolate = save
// later compiles use defaults again
Code
Lodash Examples
Short, copy-ready snippets from the official _.template docs. Open DevTools, or use Try It Yourself for a live editor.
Example 1 — Official: Custom Interpolate Delimiters
Change templateSettings.interpolate to Mustache-style {{ }} tags.
Lodash
_.templateSettings.interpolate = /{{([\s\S]+?)}}/g;
var compiled = _.template('hello {{ user }}!');
compiled({ 'user': 'mustache' });
// → 'hello mustache!'
Option.{ variable: 'data' } overrides settings for this compile.
Template. Expressions must use data.user, not bare user.
Benefit. Compiled source avoids with — clearer and stricter.
Global. You can also set _.templateSettings.variable.
Edge Cases & Pitfalls
Watch for these when changing _.templateSettings.
security
Never compile untrusted templates
_.template builds executable functions. Use only developer-controlled strings. Lodash documents this as insecure and plans removal in v5.
global
Settings changes stick
Assigning _.templateSettings.interpolate affects later compiles. Prefer per-call options, or save/restore around temporary changes.
names
escape vs interpolate naming
In Lodash, the escape delimiter (<%- %>) HTML-escapes. The interpolate delimiter (<%= %>) inserts raw values. Do not reverse them.
timing
Settings apply at compile time
Changing settings after _.template() does not update already-compiled functions. Recompile to pick up new delimiters.
Compatibility
Browser & Runtime Support
_.templateSettings ships with Lodash full builds (stable in 4.x). It configures _.template, which runs anywhere Lodash runs — modern browsers (CDN or bundle) and Node.js / Bun / Deno with npm install lodash.
Available on the [email protected] namespace object. Works in evergreen browsers and current Node LTS when Lodash is installed. Treat _.template as legacy for untrusted input.
100%With Lodash 4.x
Google ChromeSupported · Desktop & Mobile
Full support
Mozilla FirefoxSupported · Desktop & Mobile
Full support
Apple SafariSupported · macOS & iOS
Full support
Microsoft EdgeSupported · Chromium
Full support
Internet ExplorerNo native support · Use a polyfill
Polyfill
OperaSupported · Modern versions
Full support
Samsung InternetSupported · Android
Full support
BunSupported · JavaScript runtime
Supported
DenoSupported · JavaScript runtime
Supported
Node.jsSupported · Server runtime
Supported
Android WebViewSupported · Modern WebView
Full support
_.templateSettingsLodash 4.x
Bottom line: Safe for configuring developer-controlled templates. Prefer per-call options over global mutation. Do not compile untrusted strings — Lodash plans to remove _.template in v5.
Analysis
Performance Notes
Approach
Cost
Best for
Compile once, reuse
O(n) compile, O(n) render
Hot paths / loops
Recompile every call
O(n) each time
Avoid in production
Per-call options
Same compile cost
Isolated delimiter changes
Changing settings is cheap; compiling is the expensive step. Compile once and reuse the function.
Remember
Key Takeaways
Role: defaults for _.template() delimiters, imports, and variable.
Tags:<%= %> raw, <%- %> escaped, <% %> evaluate.
Override: per-call options beat global settings.
Warning: trusted templates only; removal planned in Lodash v5.
One line:_.templateSettings holds the default delimiters and options that _.template() uses unless you override them per call.
Frequently Asked Questions
_.templateSettings is the object of default options used by _.template(): escape, evaluate, interpolate RegExps, plus imports and variable.
<%= %> interpolates unescaped values. <%- %> HTML-escapes values (escape delimiter). <% %> evaluates JavaScript without printing by default.
Yes. Options passed to _.template(string, options) take precedence over _.templateSettings for that compile.
Yes. Assignments stick for later compiles in the same Lodash instance. Prefer per-call options, or restore the previous RegExp after a temporary change.
No. Compiling untrusted template strings can execute code. Use only developer-controlled templates and trusted data. Lodash plans to remove _.template in v5.
Use the full build: import _ from "lodash" then _.templateSettings. Modular lodash/template still reads the settings object from its build.