Skip to content

Syntax Change Delimiter

thegrandpoobah edited this page Jun 20, 2012 · 4 revisions

Mustache Syntax: Change Delimiter

Description

By default, Mustache treats the {{ token as the start of a Mustache tag and the }} token as the end of a Mustache tag. However, for scenarios where those tokens need to be used in the template, Mustache provides the Change Delimiter tag to change the tokens to other characters, allowing the template to make sure of the special {{ and }} tokens. Changing the delimiters has a particular scope both in terms of affected tag types (as outlined on each individual tag type page documentation) and how long the change stays in affect for.

The Change Delimiter tag starts with the {{= token and ends with the =}} token. The format of the tag is as follows:

{{=<new_open_token> <new_close_token>=}}

Where <new_open_token> and <new_close_token> are both strings that do not contain white space characters separated by white space.

Once the delimiters have been changed, the change stays in effect until the end of the template or partial, but does not affect the contents of a partial. All other tags are affected by the Change Delimiter tag.

The Change Delimiter tag obeys the Change Delimiter tag. That is, once the delimiter is changed, to change it back, you must use the Change Delimiter tag to reset it back as follows:

<new_open_token>={{ }}=<new_close_token>

Examples

Change the open tag from {{ to @@:

{{=@@ }}=}}
@@bugs_bunny}} 

Change the close tag from }} to @@:

{{={{ @@=}}
{{bugs_bunny@@

Given the following base template:

{{! Partials reset the delimiter back to {{ and }} !}}
{{=(( ))=}}
((>partial))

And the following partial:

((bugs_bunny))

The bugs_bunny interpolation tag will not be parsed as expected since the Change Delimiter does not have scope inside the partial.

Change Delimiter tags obey the Change Delimiter tag:

{{=@@ @@=}}
    @@! Change Delimiter tags obey the change delimiter tag !@@
@@={{ }}=@@
Clone this wiki locally