最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

javascript - How to escape characters in Handlebars - Stack Overflow

matteradmin8PV0评论

I have "name" variable in the view and I want to display something like this in the rendered HTML:

${Jon}

Right now, my code is like this:

<li>
  {{name}}
</li>

I am storing name in the view directly as "${" + model.name + "}". But I dont want to store names this way, I want to display the characters $, { and } in the handlebars template.

How to you escape { and } in the handlebars to be normal strings?

I have "name" variable in the view and I want to display something like this in the rendered HTML:

${Jon}

Right now, my code is like this:

<li>
  {{name}}
</li>

I am storing name in the view directly as "${" + model.name + "}". But I dont want to store names this way, I want to display the characters $, { and } in the handlebars template.

How to you escape { and } in the handlebars to be normal strings?

Share Improve this question asked Apr 29, 2013 at 5:34 Dhwaneet BhattDhwaneet Bhatt 5861 gold badge8 silver badges19 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 4

You can use the HTML ASCII code:

&#123; = '{'
&#125; = '}'

example:

<li>&#123;{{item}}&#125;</li>

if item = 'apple', then this bees:

{apple}

JSBin example

Post a comment

comment list (0)

  1. No comments so far