1

我在玩 Nodejs,想知道我是否可以使用翡翠风格的速记(即

a(href='/page?name=contact')

作为传递到玉文件的参数的一部分。


例如,假设我想写一些类似(来自 Ninja Store 示例)的内容:

 var name = req.query.name;
    var contents = {
        about: 'a(href="/page?name=about") Ninja Store \n sells the coolest ninja stuff in the world. Anyone shopping here is cool.',
        contact: 'You can contact us at <address><strong>Ninja Store</strong>,<br>1, World Ninja Headquarters,<br>Ninja Avenue,<br>NIN80B7-JP,<br>Nihongo.</address>'
    };
res.render('page', { title: 'Ninja Store - ' + name, username: req.session.username, content:contents[name] });

有没有一种机制可以用来编写这种风格的代码?

4

1 回答 1

2

您必须编译字符串

var jade = require('jade');

// ...

var contents = {
    about: jade.compile('a(href="/page?name=about") ...')(),
    contact: 'You can contact us at ...'
};

但是,您可以只在视图之间切换,而不是将它们存储在contents

res.render(name, {
    title: 'Ninja Store - ' + name,
    username: req.session.username
});

而且,您仍然可以将它们包含在page.jade模板继承中。

page.jade:

#container
    block contents

关于.jade:

inherits page

block contents
    a(href="/page?name=about") Ninja Store
    span sells the coolest ninja stuff in the world. Anyone shopping here is cool.
于 2012-04-24T20:04:48.323 回答