V
V
Vyacheslav Lebedev2015-04-25 18:44:11
Pug
Vyacheslav Lebedev, 2015-04-25 18:44:11

Jade, compileFile and render on server side?

Good evening!
Faced the problem of compiling the jade file to html, namely, the subsequent display on the client side.
Here is a code example to make it clearer:

var fn, html, item, store;
fn = jade.compileFile(views + "templates/container.jade");
store = getStore.getStore();

html = '';
for (item in store) {
  html += fn(store[item]);
}
console.log(html);

So. There is a template "container.jade", I compile it and get html.
Now I'm trying to implement this in the main index file. To display the entire page, but I can not figure out how to do it.
app.get('/', function(req, res) {
  return res.render('index');
});

All that comes to my mind is to write the resulting html to a file and include something like this in the index:
include templates/containerand give the index to render, but this operation is too "expensive".
Please advise how can I solve this problem?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question