The _.template()
function accepts settings
as a third argument, allowing you to change a few things about how do the templates work, including making the templates more Moustache-like. But is this all the settings can do? Can you provide a full list of keys and their meanings for the settings object? And is it possible to compile settings into a template (since the data
argument goes before settings
, it seems that providing settings along with a template would result in underscore trying to apply a template immediately, assuming settings to be the data).
But is this all the settings can do?
Yes, all possible settings
are mentioned in the docs. You can read the annoted source as well.
Can you provide a full list of keys and their meanings for the settings object?
interpolate
: regex to match expressions that should be interpolated verbatimescape
: regex to match expressions that should be inserted after being HTML escapedevaluate
: regex to match expressions that should be evaluated without insertion into the resulting string.variable
: A variable name to access the data as properties, instead of using a with
statementAnd is it possible to compile settings into a template?
Yes. Simply pass any falsy value (null
, undefined
, false
, …) for data
and the method will return a template function instead of rendering it right away.