# a-simple-templater

> make a simple templated website

Latest version **1.0.7** (published 2015-05-21) · BSD license · 0 weekly downloads

## Install

```sh
npm install a-simple-templater
pnpm add a-simple-templater
yarn add a-simple-templater
bun add a-simple-templater
```

## 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.7 |
| Published | 2015-05-21 |
| First published | 2015-05-20 |
| Weekly downloads | 0 |
| License | BSD |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Karissa McKelvey |
| Maintainers | karissa |
| Keywords | templates, node.js |

## Links

- npm: https://www.npmjs.com/package/a-simple-templater
- Repository: https://github.com/karissa/a-simple-templater
- Issues: https://github.com/karissa/a-simple-templater/issues
- npm.io page: https://npm.io/package/a-simple-templater

## Dependencies (3)

- [dom](https://npm.io/package/dom.md) 0.0.3
- [page](https://npm.io/package/page.md) ^1.6.3
- [mustache](https://npm.io/package/mustache.md) ^2.0.0

## Recent versions

- 1.0.7 (latest) — 2015-05-21
- 1.0.6 — 2015-05-20
- 1.0.5 — 2015-05-20
- 1.0.4 — 2015-05-20
- 1.0.3 — 2015-05-20
- 1.0.2 — 2015-05-20
- 1.0.1 — 2015-05-20
- 1.0.0 — 2015-05-20

## README

# a-simple-templater

[![NPM](https://nodei.co/npm/a-simple-templater.png)](https://nodei.co/npm/a-simple-templater/)

Make your routes. Uses mustache templates by default.

Your index.js
```js
var templater = require('a-simple-templater');
var fs = require('fs')

var routes = [
  {
    url: '/',
    template: '<h1>{{title}}</h1>',
    data: function (params, cb)  {
      cb({
        title: 'hey whats up ' + params.id
      })
    }
  },
  {
    url: '/hello/:id',
    template: fs.readFileSync('templates/blog.html').toString(),
    data: function (params, cb) {
      cb({
        greeting: 'hello',
        place: 'world'
      })
    },
    onrender: function (params, data) {
      console.log('hello', data.place, params.id)
    }
  }
]

templater('#content', routes)
```

Your index.html
```html
<html>
<body>
  <div id="content"></div>
  <script type="text/javascript" src="/bundle.js"></script>
</body>
</html>
```

### A trick for gh-pages:

Rename index.html to 404.html and then symlink index to 404.
```
ln -s 404.html index.html
```

### Overriding the default rendering engine (mustache) to use handlebars, for example:
```js
var Handlebars = require('handlebars')
templater('#content', routes, function (source, data) {
  var template = Handlebars.compile(source)
  return template(data)
})
```

### TODO
  * handle 404s correctly. make the 404.html trick for gh-pages not be necessary

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