# vtpl

> a tiny template engine

Latest version **1.1.2** (published 2023-02-05) · MIT license · 0 weekly downloads

## Install

```sh
npm install vtpl
pnpm add vtpl
yarn add vtpl
bun add vtpl
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.2 |
| Published | 2023-02-05 |
| First published | 2016-07-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 43.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | fengzilong |
| Maintainers | fengzilong |
| Keywords | template, engine, tiny, v, vtpl |

## Links

- npm: https://www.npmjs.com/package/vtpl
- Repository: https://github.com/fengzilong/v
- Homepage: https://github.com/fengzilong/v#readme
- Issues: https://github.com/fengzilong/v/issues
- npm.io page: https://npm.io/package/vtpl

## Recent versions

- 1.1.2 (latest) — 2023-02-05
- 1.1.1 — 2023-02-05
- 1.1.0 — 2023-02-05
- 1.0.0 — 2023-02-01
- 0.0.7 — 2020-06-23
- 0.0.6 — 2016-07-24
- 0.0.5 — 2016-07-24
- 0.0.4 — 2016-07-22
- 0.0.3 — 2016-07-22
- 0.0.2 — 2016-07-17
- 0.0.1 — 2016-07-17
- 0.0.0 — 2016-07-15

## README

# v [![npm package][npm-package-image]][npm-package-url] [![size][size-image]][size-url]

> a tiny template engine

## Installation

```bash
$ npm i vtpl
```

## Template Syntax

### if / else

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

### each

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

### interpolation

```js
{{ 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

```js
{{= expr}}
```

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

```js
v.config( 'escape', false );
```

### filter

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

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

Here is an example for filter1 above

```js
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

key | value
------- | -----------
openTag | string
closeTag | string
escape | boolean

### v.registerFilter( name, fn )

#### name

Type: `string`

#### fn

Type: `function`

### v.config( key, value )

#### key

Type: `string`

#### value

Type: `string` or `boolean`

key | value
------- | -----------
openTag | string
closeTag | string
escape | boolean

## License

MIT © [fengzilong](https://github.com/fengzilong/v)

[size-image]: https://img.shields.io/bundlephobia/minzip/vtpl?color=%2322ce42&style=flat-square
[size-url]: https://unpkg.com/browse/vtpl/

[npm-package-image]: https://img.shields.io/npm/v/vtpl.svg?style=flat-square
[npm-package-url]: https://www.npmjs.org/package/vtpl

---
_Source: https://npm.io/package/vtpl · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
