https://github.com/creeperyang/sugar-template
JavaScript template based on `mustache`
https://github.com/creeperyang/sugar-template
mustache mustache-templates template template-engine
Last synced: 3 months ago
JSON representation
JavaScript template based on `mustache`
- Host: GitHub
- URL: https://github.com/creeperyang/sugar-template
- Owner: creeperyang
- Created: 2016-06-17T07:20:57.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-04-07T11:27:00.000Z (over 8 years ago)
- Last Synced: 2025-05-09T08:57:02.304Z (5 months ago)
- Topics: mustache, mustache-templates, template, template-engine
- Language: JavaScript
- Size: 61.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: changelog.md
Awesome Lists containing this project
README
# sugar-template[](https://travis-ci.org/creeperyang/sugar-template)
> A simple template engine based on `mustache.js`.
## Install
[](https://nodei.co/npm/sugar-template/)
## Usage
```js
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
1. Expression, `{{varialbe}}`, starts with `{{` and ends with `}}`.
2. HTML escaping. Normal expression will be automatically escaped. So, use `{{{varialbe}}}` if you don't wanna escaping.
3. Helpers. Almost like `handlebars`, `{{#helper context}} {{/helper}}`.
4. Inline helpers. `{{helper context}}`.
5. Filters. `{{context | filter}}`.
6. 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