Node.js + Express - How to Get Partial Mustache Parts?

I'm trying to get Mustache to work with Express, and as you might guess, I'm having problems.

The next line initializes Mustache clean and clean. Variables are displayed as expected.

app.register('html', require(__dirname+'/public/js/libs/mustache.js'));

Nevertheless, problems begin to grow when partial ones rush into the mix. With the help of the Mustache, this here is partially due to cause the title / partial representation.

{{> header}}

But alas, nothing happens.: / Even when I propose a partial line, the Mustache cannot display it.

app.get('/', function(req, res) {
    res.render('welcome', {
        partials: {
            header: '<h1>Header</h1>'           
        }
    });
});

So, it seems that the particles do not work at all. I found one hack that partially processes partial files:

http://bitdrift.com/post/2376383378/using-mustache-templates-in-express

, (. ), /:

:

Behold, the header
{{> header}}
<p>Let move to more important stuff...</p>

:

<h1>Header</h1>

Express , , ...

+5
2

hogan-express.

https://github.com/vol4ok/hogan-express

, , hogan-express . .

+2

, ./public/js/libs/mustache.js... npm + templating .

, app.register, mustache.to_html(template, locals, partials) - .

partials to_html.

0

All Articles