将html元素传递到一个玉文件
是否有可能将HTML元素传递到一个翡翠文件,例如我想要以下内容填充文本的p元素,以及嵌套在p元素内的一些包含文本的代码元素。
包含string的JSON
var news = { one : { title : "Using JSON", body : "Using JSON is a great way of passing information into the jade template files."+ "It can be looped over using jades each syntax <code>test</code>" }, two : { title : "", body : "" } }
路由HTTP请求
// Routes app.get(navigation.home.uri, function(req, res){ //Home res.render(navigation.home.url, { title: navigation.home.title, navigation: navigation, news: news }); });
Jade文件片段,每个新闻项目都有一个循环
section#news - each item in news article(class="news") header h2 #{item.title} p #{item.body}
使用!{item.body}
而不是#
被接受的答案对于@Jack给出的例子确实是正确的,但是我没有使用初始的p
标签:
block content .jumbotron !{template.sections.welcome} .panel.panel-default !{template.sections.headline}
这是不正确的,会抛出一些像玉警告
Warning: missing space before text for line 6 of jade file "~/demo/views/home.jade"
这是因为不是使用未转义的缓冲区代码 ,而是使用插值的,用于长string。
所以正确的语法( 这里解释)是:
block content .jumbotron != template.sections.welcome .panel.panel-default != template.sections.headline
希望这可以节省一些时间,试图达到这些警告的底部!