A module to render a string using Mustache templating.
stache-render provides a flexible way to render content from template and partials all in one request.
Pass in any combination of file paths and strings. Use the simple and familiar mustache template syntax.
Note: the render function is an
asyncfunction.
npm i stache-render
With template file
constrender=require("stache-render");consttemplate={src: "path/to/template.tmpl"};constsomeData={greeting: "Hello",name: "World"};constcontent=awaitrender(template,someData);With string
constrender=require("stache-render");consttemplate={content: "Guess what? {{answer}}"};constsomeData={answer: "Chicken butt"};constcontent=awaitrender(template,someData);Template Parameter Schema
Note: each template item can have a
srcproperty which specifies a filepath ORcontentproperty containing a template string.
An array of partials may optionally be included, if you're into that sort of thing. Each partial follows the same convention, it can have a src OR content property. Additionally, it must have a name property, so it can be matched in the template.
{src: "/path/to/template",content: "Hello {{name}}, this is a template. {{> header}}",partials: [{name: "header",content: "This is a partial and don't you forget it"}]}