1.1.2 • Published 1 year ago

vtpl v1.1.2

Weekly downloads
2
License
MIT
Repository
github
Last release
1 year ago

v npm package size

a tiny template engine

Installation

$ npm i vtpl

Template Syntax

if / else

{{if expr1}}
	expr1 is true
{{else if expr2}}
	expr1 is false and expr2 is true
{{else}}
	expr1 and expr2 are both false
{{/if}}

each

{{each arrayOrObject as v, k}}
	{{ v }}
{{/each}}

interpolation

{{ v }}
{{ v + 'tail' }}
{{ a || b }}
{{ a && b }}
{{ Date.now() }}
{{ Math.round( num ) }}
{{ boolean ? a : b }}
...

All interpolations will be escaped automatically by default, if you want to disable this feature, add = at the start of your interpolation

For example

{{= expr}}

You can also disable this feature in global scope, by adding following code before compiling your template

v.config( 'escape', false );

filter

{{ expr | filter1: param1, param2 | filter2 | ... }}

If you want to register your own filter, use v.registerFilter

Here is an example for filter1 above

v.registerFilter( 'filter1', function( str, param1, param2 ) {
	return str + param1 + param2;
} );

API

v.compile( template, options )

template

Type: string

options

options here has priority over global config

keyvalue
openTagstring
closeTagstring
escapeboolean

v.registerFilter( name, fn )

name

Type: string

fn

Type: function

v.config( key, value )

key

Type: string

value

Type: string or boolean

keyvalue
openTagstring
closeTagstring
escapeboolean

License

MIT © fengzilong

1.1.1

1 year ago

1.1.0

1 year ago

1.0.0

1 year ago

1.1.2

1 year ago

0.0.7

4 years ago

0.0.6

8 years ago

0.0.5

8 years ago

0.0.4

8 years ago

0.0.3

8 years ago

0.0.2

8 years ago

0.0.1

8 years ago

0.0.0

8 years ago