# tiny-template-engine

> a weak template engine, and we can use it to render some simple text;

Latest version **1.0.1** (published 2021-03-27) · ISC license · 0 weekly downloads

## Install

```sh
npm install tiny-template-engine
pnpm add tiny-template-engine
yarn add tiny-template-engine
bun add tiny-template-engine
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2021-03-27 |
| First published | 2021-03-27 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 3.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | kilicmu |

## Links

- npm: https://www.npmjs.com/package/tiny-template-engine
- Repository: https://github.com/kilicmu/tinyTemplateEngine
- Homepage: https://github.com/kilicmu/tinyTemplateEngine#readme
- Issues: https://github.com/kilicmu/tinyTemplateEngine/issues
- npm.io page: https://npm.io/package/tiny-template-engine

## Dependencies (1)

- [mime](https://npm.io/package/mime.md) ^2.5.2

## Recent versions

- 1.0.1 (latest) — 2021-03-27
- 1.0.0 — 2021-03-27

## README

## Tiny template engine

a weak template engine, and we can use it to render some simple text 😆

only use for study! 😅

### tmplate expression

support get var: 
```html
    <p>{{data}}</p>
```

support js expression in html, for example to render an array list:
```html
<ul>
    {% [1,2,3,4].forEach((item) => {%}
        {% if(item === 1 || item === 3) { %}
            {% return %}
        {% } else { %}
            <li>{{item}}</li>
        {% } %}
    {% }) %}
</ul>
```

### use example:
```js
const { readFileSync } = require('fs');
const { resolve } = require('path');
const { render } = require('src/index.js');
const http = require('http');
const mime = require('mime');

http.createServer(function (request, response) {
    const tmplPath = resolve(__dirname, '/src/tmpl.html');
    const tmpl = readFileSync(tmplPath, 'utf8');
    const data = { arr: [1, 2, 3, 4] };
    response.writeHead(200, { 'Content-Type': mime.getType(tmplPath) });
    response.end(render(tmpl, data));
}).listen(8081);

console.log('Server running at http://127.0.0.1:8081/');
```

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