Tiddo
Tiddo

Reputation: 6564

NodeJS & mustache: how to get partials working?

I want to use mustache with node, but for some reason partials won't work: I've created 2 files, app.js and test.mustache, both in the same directory. Using a package.json file and npm I've installed the latest version of mustache for this project. The files look like this:

app.js:

var mus = require('mustache');
console.log(mus.render('test.mustache: {{>test}}'));

test.mustache:

This is a test

If I run node app.js I expect to get the following output: test.mustache: This is a test, but instead I just get: test.mustache:.

Other mustache tags do work as expected, and even the vows test of mustache doesn't report any errors.

What should I do to get this to work correctly?

Upvotes: 2

Views: 1168

Answers (2)

Sam3k
Sam3k

Reputation: 950

FYI, this version of Consolidate.js supports partials: https://github.com/simov/consolidate.js

Consolidate makes it easy to use many templating engines inside Express.js

Upvotes: 0

Tiddo
Tiddo

Reputation: 6564

Using node-inspector I've debugged the above application with Mustache. It turns out that Mustache doesn't automatically include the partial files, in contrary to what the manual implies (scroll down to partials). Instead you'll always need to provide the partials manually as the third argument to the render method.

Upvotes: 6

Related Questions