Do you have your mustache templates in a subdirectory tree of your project like so?
templates
├── more
│ └── def.mustache
├── some
│ ├── others
│ │ └── klm.mustache
│ └── xyz.txt
├── abc.mustache
└── uvw.js
Do you want to reference them in an easy way in your code like so?
mustache.render(templates.some.others.klm, view);
Just require mustache-dictionary
and call it on your target directory.
var mustacheDictionary = require('mustache-dictionary');
var templates = mustacheDictionary('templates');
This will load your templates and return an object of the following form
{
more: {
def: '<content of def.mustache>'
},
some: {
others: {
klm: '<content of klm.mustache>'
}
},
abc: '<content of abc.mustache>'
}
npm install mustache-dictionary --save
If you need to extend the functionality of mustache-dictionary
please feel free to contribute!
git clone https://github.com/mkretz/mustache-dictionary.git
npm test