# mini-template-engine

> mini template engine

Latest version **1.3.5** (published 2015-06-30) · MIT license · 0 weekly downloads

## Install

```sh
npm install mini-template-engine
pnpm add mini-template-engine
yarn add mini-template-engine
bun add mini-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.3.5 |
| Published | 2015-06-30 |
| First published | 2015-06-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Bjarne Oeverli |
| Maintainers | bjarneo |
| Keywords | template, mini, engine |

## Links

- npm: https://www.npmjs.com/package/mini-template-engine
- Repository: https://github.com/bjarneo/mini-template-engine
- Issues: https://github.com/bjarneo/mini-template-engine/issues
- npm.io page: https://npm.io/package/mini-template-engine

## Dependencies (3)

- [is-object](https://npm.io/package/is-object.md) ~1.0.1
- [is-string](https://npm.io/package/is-string.md) ^1.0.4
- [is-function](https://npm.io/package/is-function.md) ^1.0.1

## Recent versions

- 1.3.5 (latest) — 2015-06-30
- 1.3.4 — 2015-06-30
- 1.2.4 — 2015-06-29
- 1.1.4 — 2015-06-27
- 1.1.3 — 2015-06-27
- 1.1.2 — 2015-06-26
- 1.1.1 — 2015-06-26
- 1.1.0 — 2015-06-26
- 1.0.0 — 2015-06-25

## README

Mini template engine.
===========
![Travis](https://travis-ci.org/bjarneo/mini-template-engine.svg?branch=master) 
[![Code Climate](https://codeclimate.com/github/bjarneo/mini-template-engine/badges/gpa.svg)](https://codeclimate.com/github/bjarneo/mini-template-engine)
<br />

This is a small easy template engine. It just replaces variable placeholders with objects passed to the function.

### Install
```javascript
npm install --save mini-template-engine
```

### Syntax
```javascript
var template = require('mini-template-engine');
template(
    'string with {placeholder}',
    { placeholder: 'to be replaced' },
    function asyncCallback(data, error) {} // Optional. If not used it'll be blocking.
);
```


### Usage
```javascript
var template = require('mini-template-engine');

var html = template(
    '<div class="{className}">{content}</div>',
    {
        className: 'wrapper',
        content: 'So this is some not so useful content'
    }
);

console.log(html);

// Template should now contain this html string:
// '<div class="wrapper">So this is some not so useful content</div>'


// Async approach
var async = template(
    '<span>{async}</span>',
    { async: 'loaded async' },
    function(template, err) {
        if (err) {
            console.log(err);
        }

        console.log(template);
    }
);

// Output: <span>loaded async</span>


// You can also use the "template" for other stuff than html also
var otherStuff = template(
    'I want to add a word dynamic: {word}',
    {
        word: 'JavaScript'
    }
);

console.log(otherStuff);

// Output:
// 'I want to add a word dynamic: JavaScript'

var nested = template(
    '<div class="{className}">{nested.content}</div>',
    {
        className: 'wrapper',
        nested: {
            content: 'So this is some not so useful content'
        }
    }
);

console.log(nested);

// Template should now contain this html string:
// '<div class="wrapper">So this is some not so useful content</div>'

```

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