Skip to content

Syntax Interpolation

thegrandpoobah edited this page Jun 20, 2012 · 4 revisions

Mustache Syntax: Interpolation

Description

Interpolation tags in Mustache are responsible for substituting a Mustache token with the underlying value in the data set. There are two types of interpolation tags; HTML Escaping and Raw. As the name implies, HTML Escaping interpolation tags ensure that the value in the data set is valid text that can be placed between HTML tags without the worry of premature tag closures. HTML Escaping interpolation tags are the default tags and are opened with the {{ token and closed with the }} token. Raw interpolation tags simply output whatever value was in the data set regardless of HTML escaping rules. These types of tags are useful for non-HTML applications of Mustache. Raw interpolation tags are opened with the {{{ token and closed with the }}} token. Alternatively, the tag can be opened with the {{& token and closed with the }} token. The content within the tags constitutes the tag name and is used to perform lookups into the data set. The tag name cannot include whitespace except as prefix or postfix. All other characters are valid tag names.

Interpolation tags obey the Change Delimiter command. Dot Notation syntax can be used as part of the Interpolation tag name.

The . tag name is reserved by the system for use by Implicit Iterators (described in the Section article).

Examples

Assuming the following data set:

{ bugs: 'This <text> has HTML in "it"' }

The interpolation tags and their outputs are:

Tag: {{bugs}}
Result: 'This &lt;text&gt; has HTML it &quot;it&quot;'

Tag: {{{ bugs }}}
Result:  'This <text> has HTML it "it"'

Tag: {{& bugs }}
Result:  'This <text> has HTML it "it"'

Note the whitespace between the tag name and the tag open and tag close tokens.

Clone this wiki locally