javascript small template
- Vars:
{{ keyname }}
- Cycle:
{% keyname %} {{.}} {% / %}
{{.}} - value of array
- Comments:
{# comment #}
{{ keyname:filter1:filter2:...:filterN }}
- lower
- upper
- escape
- trim
- capitalize
- party
{{ keyname:default(test) }}
if no keyname in data, keyname value replace by "test"
var template = "<h1>Category: {{category}}</h1>\n" + "<ol>\n" + "{# items must be non-empty for valid markup #}" + "{% items %}" + " <li>{{ . }}</li>\n" + "{% / %}" + "</ol>\n"; var result = render(template, { category: "Fruits", items: ["Mango", "Banana", "Orange" ] });
<h1>Category: Fruits</h1> <ol> <li>Mango</li> <li>Banana</li> <li>Orange</li> </ol>
var template = "<table>\n" + "{% table %}" + " <tr>\n" + " {% . %}" + "<td>{{ . }}</td>" + "{% / %}" + "\n </tr>\n" + "{% / %}"+ "</table>\n"; var data = { table : [[1,2,3], [4,5,6]] }; var result = render(template, data);
<table> <tr> <td>1</td><td>2</td><td>3</td> </tr> <tr> <td>4</td><td>5</td><td>6</td> </tr> </table>