Simple logic-less template engine.
Methods
(static) parseTemplate(content, valuesnon-null, opt_prefixopt) → {string}
Parses template text content.
- Source:
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
content |
string
|
The template text content. | |
values |
Object
|
The template values as dict. | |
opt_prefix |
string
|
<optional> |
The optional var name prefix. |
Returns:
- Type:
-
string
Returns parsed template text content.
Example
const values = {
'date': '2013-07-18',
'user': {'name': 'John'},
'func': () => {return 'Hello World.';}
};
const content = '{{ date }} {{ user.name }} {{ func }} {{ empty|default }}';
document.getElementById('div').innerHTML = parseTemplate(content, values);