Seth Ladd
Seth Ladd

Reputation: 120539

How do I escape mustache syntax?

Assuming I have some mustache template code like this:

{{#list}}
  <p>
  This should be replaced: {{name}}
  This is not replaced: \{{example}}   <== this doesn't work, just for illustration
  </p>
{{/list}}

I'd like the output to look something like:

<p>
This should be replaced: Bob
This is not replaced: {{example}}
</p>

How do I escape syntax that looks like mustache code so that it is rendered as literal {{ and }} ?

Upvotes: 2

Views: 492

Answers (1)

Mathias Begert
Mathias Begert

Reputation: 2471

There is no built-in escaping mechanism (as far as I know), but you could temporarily change the tag delimiter:

{{#list}}
  <p>
  This should be replaced: {{name}}
  This is not replaced: {{=<% %>=}}{{example}}<%={{ }}=%>
  </p>
{{/list}}

Or use HTML escapes:

This is not replaced: &#123;&#123;example&#125;&#125;

Upvotes: 1

Related Questions