jade为不一样的需求提供了一些特殊的操做符。详见Githubhtml
=
将右边的值赋予左边,或者替换为右边变量的值。git
//- 赋值,js格式便可。 - var title = "On Dogs: Man's Best Friend"; //- 替换,注意左边无空格右边需有空格。 h= title
#{val}
将引用处替换为val变量的值。github
- var author = "Tom"; //- 编译生成的html中为Tom,而不是#{author} p Written with love by #{author}
在属性那一章的特殊属性中曾提到,相似<
这样的特殊符号编译后将为<
。一样在使用#{val}
的时候,若val变量的值含有这些特殊符号的时候,编译也会变成<
这样的形式。
为了不出现如上形式,能够采用!{val}
。数组
jade:this
- var riskyBusiness = "<em>Some of the girls are wearing my mother's clothing.</em>"; .quote p Joel: !{riskyBusiness}
html:code
<div class="quote"> <p>Joel: <em>Some of the girls are wearing my mother's clothing.</em></p> </div>
若是须要在文本内容中插入标签的话,能够使用#[...]
。htm
jade:jade
p. If you take a look at this page's source #[a(target="_blank", href="https://github.com/jadejs/jade/blob/master/docs/views/reference/interpolation.jade") on GitHub], you'll see several places where the tag interpolation operator is used, like so.
html:get
<p>If you take a look at this page's source <a target="_blank" href="https://github.com/jadejs/jade/blob/master/docs/views/reference/interpolation.jade">on GitHub</a>, you'll see several places where the tag interpolation operator is used, like so. </p>
jade支持for / while / each三种循环方式,其中for / while均与常见的循环同样。it
each循环能够用来遍历整个数组。
jade:
- var name = ['Tom', 'Jim', 'Alex', 'Jack']; each i in name p= i
html:
<p>Tom</p> <p>Jim</p> <p>Alex</p> <p>Jack</p>