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

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

问题描述

我在视图中有name"变量,我想在呈现的 HTML 中显示类似的内容:

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>

我在视图中直接将 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',那么就变成:

{苹果}

JSBin 示例

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

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