medium-templater
It's like a tiny-templater but with a little dash of logic.
usage
var language = var template_string template compile template_string = '<ul>' + '{% for item in items %}' + '<li>{% if item.okay %}okay{% else %}not okay{% endif %}</li>' + '{% endfor %}' + '</ul>' + '{{ message }}' compile = template = var result = console // <ul><li>okay</li><li>not okay</li></ul>hello world
extending
Though you get if
and for
for free, you can also provide your own tags
(or override the defaults if you don't like how they work!) like so:
index.js
var language = reverse =
./lib/reverse.js
moduleexports = reverse { var contents = '' parser return { // context is what is passed to the template, irrelevant in this example. return } { contents = tpl }}
now you can:
{% reverse %}!sredner etalpmet eht nehw thgir eb lliw txet siht{% endreverse %}
further options
Specifying reversed
at the end of a for statement
(ie for item in items reversed
) will parse the items in reverse. Specifying
an {% empty %}
tag after the {% for ... %}
will return that chunk in the
event of no items.
license
MIT