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

kuldeepdhaka picture kuldeepdhaka  路  9Comments

ForbesLindesay picture ForbesLindesay  路  14Comments

SmasherHell picture SmasherHell  路  18Comments

mbrodala picture mbrodala  路  16Comments

rlightner picture rlightner  路  7Comments