My object looks like this:
[\'foo\',\'bar\',\'baz\']
And I want to use a mustache template to produce from it something like this:
Following are the examples to render multi-dimensional array in a template:
Example 1
'use strict';
var Mustache = require('mustache');
var view = {test: 'div content', multiple : ['foo', 'bar'], multiple_2 : ['hello', 'world']};
var template = '{{test}}{{#multiple}}- {{.}}
{{/multiple}}
{{#multiple_2}}- {{.}}
{{/multiple_2}}
';
var output = Mustache.render(template, view);
console.log(output);
Example 2
'use strict';
var Mustache = require('mustache');
var view = {test: 'div content', multiple : [{name: 'foo', gender: 'male'}, {name: 'bar', gender: 'female'}], multiple_2 : [{text: 'Hello', append: '**', prepend: '**'}, {text: 'World', append: '**', prepend: '**'}]};
var template = '{{test}}{{#multiple}}- Hello my name is {{name}}. And I am {{gender}}
{{/multiple}}
{{#multiple_2}}- {{prepend}}_{{text}}_{{append}}
{{/multiple_2}}
';
var output = Mustache.render(template, view);
console.log(output);
For test run, save above examples in file called 'test.js', run following command in commandline
nodejs test.js