# native-templater

> A simple templating library for easy, native HTML templating. (Strict Version)

Latest version **1.0.0** (published 2021-01-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install native-templater
pnpm add native-templater
yarn add native-templater
bun add native-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.0 |
| Published | 2021-01-01 |
| First published | 2021-01-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 5.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Peter Johnson |
| Maintainers | peterjohnson |
| Keywords | templating, express, expressjs |

## Links

- npm: https://www.npmjs.com/package/native-templater
- npm.io page: https://npm.io/package/native-templater

## Recent versions

- 1.0.0 (latest) — 2021-01-01

## README

# Native Templater (Strict)
A simple library for easy but customizable templating. (Strict version)

For a more lenient version of NT: (COMING OUT SOON)

## Getting started:

First install Native Templater with the following command:

`npm install native-templater`

### Code Example:
#### TEM file:

```
<h1>{ heading1 } { heading2 } { heading3 }</h1>
```

#### JavaScript file:
```
const template = require(‘native-templater’)

template.render(“./index.tem”, {heading1: “This”, heading3: “Awesome!”, heading2: “Is”}, function(err, res) {
	if (err != null) {
	console.log(err)
	return;
	}
	console.log(res);
}}
```

# How to Render with Native Templater

Native template has two rendering functions, `render` and `renderAsync`. The default, `render` function is callback based, while `renderAsync` will return the rendered code and can easily be assigned to a variable. Here is an adaptation of the previous example, using `renderAsync`.

```
const template = require(‘native-templater’)

var render = template.renderAsync(“./index.tem”, {heading1: “This”, heading3: “Awesome!”, heading2: “Is”})

if (render.err != null) {
	console.log(render.err)
} else {
	console.log(render.res)
}
```

`renderAsync` is object-based, to avoid having a confusing array or returning an error in the form of the rendered code, which has a type of array, meaning you’d have to check if the response was type array. Yuck.

# Templating Syntax


Native Templater can take any language type and template it, and is easy to integrate in with Express. All templates look like this

```
{ VARIABLE }
```

The first curly-bracket tells Native Templater that it is the start of a template. Anything inside the template will be replaced (including the curly brackets & any spaces inside of the curly brackets).

# Providing Data to Native Templater

When you want to render your template, you need to give Native Templater an object full of your variables.

The format of the rendering looks like this:

```
template.render(FILEDIR, OBJECT, CALLBACK)
```

The object for the example above will look like this:

```
{heading1: “This”, heading2: “Is”, heading3: “Awesome!”}
```

You don’t need to place your tags in any particular order.

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