Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to print literal { in front of mustache variable? #357

Closed
connor11528 opened this issue Feb 16, 2014 · 3 comments
Closed

how to print literal { in front of mustache variable? #357

connor11528 opened this issue Feb 16, 2014 · 3 comments

Comments

@connor11528
Copy link

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?

@alanhamlett
Copy link

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);
    
  2. use variables to print { and }

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

@bobthecow
Copy link

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

@connor11528
Copy link
Author

this all works. thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants