rift-template
v3.5.2
Published
rift-template
Downloads
11
Readme
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:
<ul>
{{~users :user }}
{{? user?.firstName }}
<li>{{user.firstName}}</li>
{{?? ln=user?.lastName }}
<li>{{ln}}</li>
{{??}}
<li>No name</li>
{{/?}}
{{/~}}
</ul>
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 }}
<li>{{name}}</li>
{{??}}
<li>No name</li>
{{/?}}
{{/@}}
<ul>
{{~users :user }}
{{=item user.firstName || user.lastName }}
{{/~}}
</ul>
{{@link :content :href }}
<a href="{{href}}">{{{content}}}</a>
{{/@}}
{{=link 'Click me!', 'http://2gis.ru/' }}
{{#link 'http://2gis.ru/' }}
Click me!
{{/#}}