Mustache.js: how to print literal { in front of mustache variable?

Created on 16 Feb 2014  ·  3Comments  ·  Source: janl/mustache.js

I have a mustache template where I would like to surround the variables with {}

var output = Mustache.render('<td>{{{start.lat}}, {{start.lon}}}</td>', routeObj);

I'd like this to output a <td> with the string: {1.8978, 30.4545}

{{{ has special meaning in mustache so it doesn't work. Is there a way to escape the first { in mustache?

Most helpful comment

Two ways I can think of:

  1. temporarily set delimiter to something besides braces, then switch it back after printing the braces

var output = Mustache.render('<td>{{=<% %>=}}{<% start.lat %>, <% start.lon %>}<%={{ }}=%></td>', routeObj);

  1. use variables to print { and }

routeObj.openbrace = '{'; routeObj.closebrace = '}'; var output = Mustache.render('<td>{{openbrace}}{{start.lat}}, {{start.lon}}{{closebrace}}</td>', routeObj);

All 3 comments

Two ways I can think of:

  1. temporarily set delimiter to something besides braces, then switch it back after printing the braces

var output = Mustache.render('<td>{{=<% %>=}}{<% start.lat %>, <% start.lon %>}<%={{ }}=%></td>', routeObj);

  1. use variables to print { and }

routeObj.openbrace = '{'; routeObj.closebrace = '}'; var output = Mustache.render('<td>{{openbrace}}{{start.lat}}, {{start.lon}}{{closebrace}}</td>', routeObj);

What @alanhamlett said, also, html entities: &#123; is {

this all works. thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

zekth picture zekth  ·  18Comments

amper5and picture amper5and  ·  5Comments

MatthijsZw picture MatthijsZw  ·  18Comments

rlightner picture rlightner  ·  7Comments

chlab picture chlab  ·  11Comments