sugar-template
v2.0.1
Published
JavaScript template engine based on mustache
Downloads
15
Maintainers
Readme
sugar-template
A simple template engine based on
mustache.js
.
Install
Usage
const sugar = require('sugar-template')
sugar.render(`{{title | uppercase}}`, { title: 'test' }) // --> 'TEST'
sugar.render(`{{#each user}}{{.}} {{/each}}`, {
user: {
name: 'Mike',
age: 18,
gender: 'M'
}
})
// --> Mike 18 M
Syntax
Expression,
{{varialbe}}
, starts with{{
and ends with}}
.HTML escaping. Normal expression will be automatically escaped. So, use
{{{varialbe}}}
if you don't wanna escaping.Helpers. Almost like
handlebars
,{{#helper context}} {{/helper}}
.Inline helpers.
{{helper context}}
.Filters.
{{context | filter}}
.Ignore Compile.
{{=text=}}
,text
here will output without any change.
API
sugar.render(String: template, Object: data)
Render template to string.
sugar.parse(String: template)
Parse template to AST.
License
MIT