I have made a single page app powered by node js (Express) with a mongo db. I have used jade for templating and have some templates rendered in the browser. The templates render fine except I am unable to workout how to add helpers. In particular i18next.
I have set up a route to template/get/ which looks like this:
var fs = require('fs');
var jade = require('jade');
exports.get = function(req, res){
fs.readFile('views/partials/listing_snippet.jade', {encoding: 'utf-8'}, function (err, data) {
if (err) throw err;
console.log(data);
t = jade.compile(data, {client: true, compileDebug: false});
res.send('var template = {listing_snippet: ' + t.toString() + '}');
});
}
I then include this and jades 'runtime.js' as scripts at the top of my page. The template renders fine by calling template.listing_snippet({locals: foo});
but I can not get i18next's helpers to work. I assume I need to attach the helper somehow... but the documentation is a little thin in that area.
Merge your helpers in your object. For example
res.send('var o = ' + t.toString() . ';' +
'import(o, my_helpers);' +
'var template = {listing_snippet: obj}');