I'm playing around with Nodejs, and am wondering if I can use jade style shorthand (ie
a(href='/page?name=contact')
as part of an argument passed into a jade file.
Say, for example, that I want to write something along the lines of (from the Ninja Store example):
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] });
Is there a mechanism I can use to write this style of code?
You'd have to compile the string:
var jade = require('jade');
// ...
var contents = {
about: jade.compile('a(href="/page?name=about") ...')(),
contact: 'You can contact us at ...'
};
However, you could just switch between views rather than storing them in contents
:
res.render(name, {
title: 'Ninja Store - ' + name,
username: req.session.username
});
Aand, you can still have them contained in page.jade
with template inheritance.
page.jade:
#container
block contents
about.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.