R
R
r2sada2r2015-06-01 20:06:44
Node.js
r2sada2r, 2015-06-01 20:06:44

Is there a callback at the end of work in mustache?

I use the mustache template engine, there is a code:

var res = mustache.render(pages['main'], {
  'country': 'Russia',
  'city': 'Moscow',
  ...
});

console.log(res);

In a template, for example, there are more than a billion inserts, how do you know that mustache has finished working?
I can’t show the res variable right away, because it may not fill up.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
Yuri Shikanov, 2015-06-01
@r2sada2r

There it looks like stream is returning, so you need something like this:

var stream = mustache.render(pages['main'], {
  'country': 'Russia',
  'city': 'Moscow',
  ...
});
var rendered_data = '';
stream.on('data', function (data) {
    rendered_data += data.toString();
});
stream.on('end', function () {
    // Шаблон отрендерен
    console.log(rendered_data);
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question