在玉模板(感叹号对象,哈希对象)中使用!{}和#{}插值 [英] Using !{ } and #{ } interpolation in a jade template (exclamation-object, hash-object)

查看:58
本文介绍了在玉模板(感叹号对象,哈希对象)中使用!{}和#{}插值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一个玉器模板中(使用对node.js的表达),我看到了一个使用以下语法的模板:

In a jade template (using express over node.js), I see a template using the following syntax:

script(type='text/template', id='data-services') !{data}

我不理解!{} 的构造;显然,它插值了在其他地方定义的javascript对象:

I don't understand the !{ } construct; apparently it interpolates a javascript object defined elsewhere as:

var data={ name:"Doe", age:"21" };

Jade docs&tut显示了使用#{} 进行插值,但是我看不到!{} .即使#{} 也没有记录,所以我认为它不是特定于玉器的.该语法从何而来?在何处得到记录?

Jade docs & tuts show the use of #{ } for interpolation, but I don't see !{ }. Even #{ } is not documented, so I think it's not jade-specific. Where does this syntax come from and where is it documented?

推荐答案

确实很难找到它.看看这个资源:

Quite difficult to find it, indeed. Have a look at this resource:

http://naltatis.github.io/jade-syntax-docs/#escaping

#用于要转义数据,而则用于原始数据.

# is used when you want to escape data and ! when you want it raw.

例如,假设 name ="Hello< em> World</em>" .然后,您将拥有:

For example let's say that name = "Hello <em>World</em>". Then you have:

#{name} --> Hello &lt;em&gt;World&lt;/em&gt;
!{name} --> Hello <em>World</em>

这样想:#将在编写时显示 name ,而将其视为HTML.

Think about it like that: # will display name as it is written while ! will treat it as HTML.

这篇关于在玉模板(感叹号对象,哈希对象)中使用!{}和#{}插值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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