如何在车把中转义字符 [英] How to escape characters in Handlebars

查看:91
本文介绍了如何在车把中转义字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在视图中有 name变量,我想在渲染的HTML中显示如下内容:

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

${Jon}

现在,我的代码如下:

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

我直接在视图中存储 name $ { + model.name +} 。但是我不想这样存储名称,我想显示字符 $ {}

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?

推荐答案

您可以使用HTML ASCII代码:

You can use the HTML ASCII code:

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

示例:

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

如果 item ='apple',则变成:


{apple}

{apple}

JSBin示例

这篇关于如何在车把中转义字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆