rift-template
Fastest and simple javascript template engine.
Syntax
{{ a.b.c }}
- escaped output
{{{ a.b.c }}}
- unescaped output
{{? a.b.c }}
- if
{{? !a.b.c }}
- if
not
{{?? a.b.c }}
- else if
{{?? !a.b.c }}
- else if
not
{{??}}
- else
{{/?[ comment ]}}
- end if
{{? varName = a.b.c }}
- if
with saving value
{{?? varName = a.b.c }}
- else if
with saving value
{{~ a.b.c :value[ :key] }}
- for
{{/~[ comment ]}}
- end for
{{@ partialName[ :param1[ :param2[ ...]]] }}
- partial
{{/@[ comment ]}}
- end partial
{{= name[ :param1[ :param2[ ...]]] }}
- call partial or helper
{{# name[ :param1[ :param2[ ...]]] }}
- call partial or helper with content
{{/#[ comment ]}}
- end call
{{> 'name' }}
- include
{{// comment }}
- comment
Examples
Loops and conditions:
{{~users :user }} {{? user?.firstName }} {{user.firstName}} {{?? ln=user?.lastName }} {{ln}} {{??}} No name {{/?}}{{/~}}
You can add a ?
character in the path expression to check the existence of property:
{{? a.b?()?.c.d?.e }} {{a.b.c.d.e}}{{/?}}
Partials:
{{@item :name }} {{? name }} {{name}} {{??}} No name {{/?}}{{/@}} {{~users :user }} {{=item user.firstName || user.lastName }}{{/~}}
{{@link :content :href }} {{{content}}}{{/@}} {{=link 'Click me!', 'http://2gis.ru/' }} {{#link 'http://2gis.ru/' }} Click me!{{/#}}