es6template
v1.0.5
Published
Easy and small template engine for the browser.
Downloads
21,151
Maintainers
Readme
es6-template
Easy and small template engine for the browser and nodejs.
Install
npm i es6-template --save
Usage
For more use-cases see the tests
var es6template = require('es6-template')
es6template
Acts like
.render
by default. Renders givenstr
withlocals
.
str
{String} template to populate withlocals
locals
{Object} locals objectreturn
{String} rendered string
Example
es6template('foo ${bar} baz ${quux}', {bar: 'BAR'}, {quux: 'QUUX'})
//=> 'foo BAR baz QUUX'
.render
Renders given
str
withlocals
. You can give unlimited number of object arguments after the first - they will be merged and passed as single locals object.
str
{String} template to populate withlocals
locals
{Object} locals objectreturn
{String} rendered string
Example
es6template.render('Hello ${place} and ${user.name}!', {
place: 'world',
user: {
name: 'Charlike'
}
})
//=> 'Hello world and Charlike!'
.compile
Compiles given string and returns function which accepts unlimited number of
locals
object arguments.
str
{String} template to populatereturn
{Function} which acceptslocals
objects
Example
var fn = es6template.compile('Hello ${place} and ${user.name}!')
fn({place: 'world', user: {name: 'Charlike'}})
//=> 'Hello world and Charlike!'
Related
- es6-template-regex: Regular expression for matching es6 template delimiters in a string.
- es6-template-strings: Compile and resolve template strings notation as specified in ES6
- gulp-es6-template: Gulp plugin for
es6-template
- easy and small template engine. - gulp-es6-template-strings: Gulp plugin for
es6-template-strings
package. - j140: Javascript template engine in just 140 bytes, for browser and node - by Jed Schmidt
- jstransformer-es6-template: es6-template support for JSTransformers
- jstransformer-es6-template-strings: es6-template-strings support for JSTransformers
Contributing
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
But before doing anything, please read the CONTRIBUTING.md guidelines.