# template_js

> A javascript template engine, simple, easy & extras, support webpack, rspack, vite, rollup, esbuild, parcel, browserify, fis and gulp.

Latest version **3.1.4** (published 2023-11-23) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.1.4 |
| Published | 2023-11-23 |
| First published | 2015-01-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=14.0.0 |
| Dependencies | 4 |
| Unpacked size | 66.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1314 |
| Author | yanhaijing |
| Maintainers | yanhaijing |
| Keywords | template, template.js, js |

## Links

- npm: https://www.npmjs.com/package/template_js
- Repository: https://github.com/yanhaijing/template.js
- Homepage: https://github.com/yanhaijing/template.js#readme
- Issues: https://github.com/yanhaijing/template.js/issues
- npm.io page: https://npm.io/package/template_js

## Dependencies (4)

- [@jsmini/type](https://npm.io/package/@jsmini/type.md) ^0.11.0
- [@jsmini/extend](https://npm.io/package/@jsmini/extend.md) ^0.5.0
- [@templatejs/parser](https://npm.io/package/@templatejs/parser.md) ^3.1.4
- [@templatejs/runtime](https://npm.io/package/@templatejs/runtime.md) ^3.1.4

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 3.1.4 (latest) — 2023-11-23
- 3.1.3-alpha.0 (next) — 2023-11-23
- 3.1.2-alpha.0 — 2023-11-23
- 3.1.0-alpha.0 — 2023-11-22
- 3.0.0-alpha.0 — 2023-11-22
- 2.8.1 — 2023-10-07
- 2.4.0 — 2019-12-18
- 2.3.0 — 2019-12-15
- 2.2.1 — 2019-12-11
- 2.1.0 — 2019-11-17
- 2.0.2 — 2019-11-09
- 2.0.2-alpha.0 — 2019-11-07
- 2.0.1-alpha.0 — 2019-11-07
- 0.8.0 — 2019-09-10
- 0.7.1-1 — 2018-04-26
- … 13 more at https://npm.io/package/template_js/versions

## README

# [template](https://github.com/yanhaijing/template.js/blob/master/packages/template)
[![](https://img.shields.io/badge/Powered%20by-jslib%20base-brightgreen.svg)](https://github.com/yanhaijing/jslib-base)

一款javascript模板引擎，简单，好用，支持webpack, rollup和fis。

## 功能概述

提供一套模板语法，用户可以写一个模板区块，每次根据传入的数据，生成对应数据产生的HTML片段，渲染不同的效果。

## :pill: 兼容性
单元测试保证支持如下环境：

| IE   | CH   | FF   | SF   | OP   | IOS  | Android   | Node  |
| ---- | ---- | ---- | ---- | ---- | ---- | ---- | ----- |
| 6+   | 29+ | 55+  | 9+   | 50+  | 9+   | 4+   | 0.10+ |

**注意：编译代码依赖ES5环境，对于ie6-8需要引入[es5-shim](http://github.com/es-shims/es5-shim/)才可以兼容，可以查看[demo/demo-global.html](./demo/demo-global.html)中的例子**

## :rocket: 使用者指南

通过npm下载安装代码

```bash
$ npm install --save template_js
```

如果你是node环境

```js
var template = require('template_js');
```

如果你是webpack等环境

```js
import template from 'template_js';
```

如果你是requirejs环境

```js
requirejs(['node_modules/template_js/dist/index.aio.js'], function (template) {
    // xxx
})
```

如果你是浏览器环境

```html
<script src="node_modules/template_js/dist/index.aio.js"></script>
```

## 快速上手

### 编写模版

使用一个type="text/html"的script标签存放模板，或者放到字符串中：

```html
<script id="tpl" type="text/html">
<ul>
    <%for(var i = 0; i < list.length; i++) {%>
        <li><%:=list[i].name%></li>
    <%}%>
</ul>
</script>
```

### 渲染模板

```js
var tpl = document.getElementById('tpl').innerHTML;
template(tpl, {list: [{name: "yan"},{name: "haijing"}]});
```

输出结果：

```html
<ul>
    <li>yan</li>
    <li>haijing</li>
</ul>
```

更多例子，请见[demo](https://github.com/yanhaijing/template.js/blob/master/packages/template/demo)目录。

## 自动化
### Fis
template.js从0.2.0开始支持[fis](http://fis.baidu.com/)，详情请看[这里](https://github.com/yanhaijing/template.js/blob/master/packages/fis-parser-template)。

### webpack
template.js从0.6.1开始支持[webpack](https://webpack.js.org/)，详情请看[这里](https://github.com/yanhaijing/template.js/blob/master/packages/template-loader)

### rollup
template.js从0.6.1开始支持[rollup](https://rollupjs.org/guide/en/)，详情请看[这里](https://github.com/yanhaijing/template.js/blob/master/packages/rollup-plugin-templatejs)

## :bookmark_tabs: 文档
[API](https://github.com/yanhaijing/template.js/blob/master/packages/template/doc/api.md)

## 贡献者列表

[contributors](https://github.com/yanhaijing/template/graphs/contributors)

## :gear: 更新日志
[CHANGELOG.md](https://github.com/yanhaijing/template.js/CHANGELOG.md)

## :airplane: 计划列表
[TODO.md](https://github.com/yanhaijing/template.js/TODO.md)

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