Lodash _.templateSettings.interpolate

Beginner
5 min read
Updated: Nov 2026
5 examples
Template

Definition

A RegExp that detects interpolate tags — spots where a JavaScript expression’s value is inserted into the template output. Default matches <%= … %>. Used by _.template().

Set the property globally, or override it per call with options passed to _.template().

Syntax

Use _.templateSettings.interpolate. Start with this line.

Lodash
_.templateSettings.interpolate
CallWhat it does
_.templateSettings.interpolatePrimary setting.
_.templateSettings.interpolate = /.../gAssign a custom RegExp or value before compiling.

Prefer the full Lodash build when using _.template() and _.templateSettings.

Library declarations
Lodash
_.templateSettings.interpolate

Parameters

ParameterDescription
_.templateSettings.interpolateOptional. (RegExp) Global default for value tags
options.interpolateOptional. (RegExp) Per-compile override
Default patternOptional. (RegExp) /<%=([\s\S]+?)%>/g

Return Value

Return ValueDescription
*RegExp (with a capture group)

Lodash Examples

Example 1 — Official: Default <%= %>

Built-in interpolate tags insert HTML-escaped values.

Lodash
var compiled = _.template('hello <%= user %>!');
compiled({ 'user': 'fred' });
// → 'hello fred!'
Try It Yourself

How It Works

  1. Default RegExp matches <%= user %>.
  2. Compile turns the tag into an escaped insert.
  3. Render with { user: 'fred' }.
  4. Result. hello fred!.

Example 2 — Official: Mustache {{ }}

Change the global interpolate RegExp to brace-style tags.

Lodash
_.templateSettings.interpolate = /{{([\s\S]+?)}}/g;

var compiled = _.template('hello {{ user }}!');
compiled({ 'user': 'pebbles' });
// → 'hello pebbles!'
Try It Yourself

How It Works

  1. Assign a RegExp with one capture group for the expression.
  2. Tags become {{ user }} instead of <%= user %>.
  3. Compile after changing the setting — order matters.
  4. Note. This mutates the global default for later compiles.

Example 3 — Per-Compile options.interpolate

Override delimiters for one template without changing globals.

Lodash
var compiled = _.template(
  'hi {{ name }}',
  { interpolate: /{{([\s\S]+?)}}/g }
);
compiled({ name: 'Ada' });
// → 'hi Ada'

// Other templates still use default <%= %>
Try It Yourself

How It Works

  1. Pass { interpolate: /{{…}}/g } to _.template.
  2. Only this compile uses brace tags.
  3. Globals stay at the ERB default.
  4. Prefer this in apps that mix delimiter styles.

Example 4 — <%= %> vs <%- %>

Interpolate escapes HTML; the escape delimiter prints raw.

Lodash
var data = { html: '<b>x</b>' };

_.template('safe=<%= html %>')(data);
// → 'safe=&lt;b&gt;x&lt;/b&gt;'

_.template('raw=<%- html %>')(data);
// → 'raw=<b>x</b>'
Try It Yourself

How It Works

  1. <%= %> uses the interpolate RegExp → output via _.escape.
  2. <%- %> uses the escape RegExp → raw string insert.
  3. User HTML should usually go through interpolate (escaped).
  4. Trusted markup can use the raw delimiter carefully.

Example 5 — Mustache Values + ERB Evaluate

Change only interpolate; keep <% %> for logic.

Lodash
var compiled = _.template(
  '<% if (vip) { %>hi {{ name }} (vip)<% } else { %>hi {{ name }}<% } %>',
  { interpolate: /{{([\s\S]+?)}}/g }
);

compiled({ name: 'Sam', vip: true });
// → 'hi Sam (vip)'

compiled({ name: 'Sam', vip: false });
// → 'hi Sam'
Try It Yourself

How It Works

  1. Evaluate still uses default <% %> for if.
  2. Interpolate uses {{ name }} only for values.
  3. One options object keeps globals untouched.
  4. Pattern. Common when you want brace values + ERB logic.

Browser & Runtime Support

_.templateSettings.interpolate is a Lodash templateSettings property used by _.template. It runs anywhere Lodash 4.x runs — modern browsers (CDN or bundle) and Node.js / Bun / Deno with npm install lodash.

✓ Stable · Lodash 4.x · Warning: template security

_.templateSettings.interpolate

Available with [email protected] full builds that include _.template. Works in evergreen browsers and current Node LTS when Lodash is installed.

100% With Lodash 4.x
Google Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Bun Supported · JavaScript runtime
Supported
Deno Supported · JavaScript runtime
Supported
Node.js Supported · Server runtime
Supported
Android WebView Supported · Modern WebView
Full support
.interpolate Lodash 4.x

Bottom line: Safe for production with trusted templates only. Prefer options.interpolate for one-off delimiter changes. Note: _.template is planned for removal in Lodash v5.

Frequently Asked Questions

It is a RegExp that detects interpolate tags — places where a JavaScript expression’s value is inserted into the output. The default matches ERB-style percent-equals tags.
A RegExp. Lodash reads the pattern at compile time. Do not assign a callback.
Set _.templateSettings.interpolate = /{{([\s\S]+?)}}/g (or pass the same RegExp as options.interpolate), then write hello {{ user }}! and render with { user: 'pebbles' }.
interpolate controls percent-equals tags (HTML-escaped insertion). escape controls percent-dash tags (raw / unescaped insertion). Different RegExps, different output safety.
At compile time. Change the RegExp before _.template() runs, or pass options.interpolate. Already-compiled functions keep their original delimiters.
No. Compiling untrusted templates can execute code. Lodash plans to remove _.template in v5.

Next: _.templateSettings.variable

Name the data object passed into compiled templates.

.variable tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

11 people found this page helpful