A simple string template.
$ npm install simple-string-template
import SimpleTemplate from 'simple-string-template';
SimpleTemplate.render(templateFile, data);
SimpleTemplate.format(templateString, data);
-
render
Defined:
function render(templateFile: String, data: Object): String
Describe: Render a template from file with data.
Examples:
A template file like this:
Hello {{ name }}
import SimpleTemplate from 'simple-string-template'; let data = { name: 'World' }; SimpleTemplate.render(templateFile, data); // return "Hello World"
-
format
Defined:
function format(templateString: String, data: Object): String
Describe: Render a template string with data.
Examples:
import SimpleTemplate from 'simple-string-template'; let templateString = "Hello {{ name }}"; let data = { name: 'World' }; SimpleTemplate.render(templateString, data); // return "Hello World"
- If you want custom your format pattern. you can like this:
import SimpleTemplate from 'simple-string-template';
let simpleTemplate = new SimpleTemplate('\\$\\{', '\\}'); // In here must be a String of RegExp.
let data = { name: 'World' };
simpleTemplate.render(templateFile, data);
simpleTemplate.format('Hello ${ name }', data);
simple-string-template is released under the MIT license.