# inject-template

> Inject template into innerHTML

Latest version **1.1.0** (published 2017-04-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install inject-template
pnpm add inject-template
yarn add inject-template
bun add inject-template
```

## 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.1.0 |
| Published | 2017-04-07 |
| First published | 2016-12-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Glenn Vandeuren |
| Maintainers | basicelements |
| Keywords | inject, template, inject-template |

## Links

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

## Recent versions

- 1.1.0 (latest) — 2017-04-07
- 1.0.2 — 2017-04-01
- 1.0.1 — 2017-04-01
- 1.0.0 — 2017-03-31
- 0.2.2 — 2017-01-07
- 0.2.1 — 2017-01-07
- 0.2.0 — 2017-01-02
- 0.1.2 — 2017-01-02
- 0.1.1 — 2016-12-29
- 0.1.0 — 2016-12-28
- 0.0.0 — 2016-12-28

## README

# inject-template [![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Dependency Status][daviddm-image]][daviddm-url] [![Coverage percentage][coveralls-image]][coveralls-url]
> Inject template into innerHTML

## Installation

```sh
$ npm install --save inject-template
```

## Usage
- An template tag in the desired element <sup>1</sup>
- An html template <sup>2</sup>

```js
var injectTemplate = require('inject-template');

let result = injectTemplate.inject({path: 'rainbow.js'}) // injects content from rainbow.html
// dosomething with result ...
```

### result
```js
class Rainbow extends HTMLElement {
  constructor() {
    super();
    this.innerHTML = 'BIG RAINBOW';
  }
  ...
}
```

#### rainbow.js <sup>1</sup>
```js
class Rainbow extends HTMLElement {
  constructor() {
    super();
    // @template rainbow
  }
  ...
}
```

#### rainbow.html <sup>2</sup>
```html
<template>
  BIG RAINBOW
</template>
```

### Named templates
```js
var injectTemplate = require('inject-template');

let result = injectTemplate.inject({path: 'rainbow.js', name: 'rainbow-template'}) // injects content from rainbow-template.html
```

### Custom templates path
```js
var injectTemplate = require('inject-template');

let result = injectTemplate.inject({path: 'rainbow.js', templatePath: 'templates'}) // injects content from templates/rainbow.html
```

## API

### injectTemplate.inject({options})
### injectTemplate.injectSync({options})
#### options

#### path
Type: `string`<br>
Default: `null`

Path to file containing the template tag

#### templatePath
Type: `string`<br>
Default: `null`

Path to the template (use when your template is in another directory).

*When undefined inject-template assumes the template in in the same directory of the element*

#### content
Type: `string`<br>
Default: `null`

The content of the element (used in [gulp-inject-html-template](https://github.com/VandeurenGlenn/gulp-inject-html-template))

*When streaming files, you can pass trough the content so inject-template doesn't need to read the element.*

## License

MIT © [Glenn Vandeuren]()


[npm-image]: https://badge.fury.io/js/inject-template.svg
[npm-url]: https://npmjs.org/package/inject-template
[travis-image]: https://travis-ci.org/VandeurenGlenn/inject-template.svg?branch=master
[travis-url]: https://travis-ci.org/VandeurenGlenn/inject-template
[daviddm-image]: https://david-dm.org/VandeurenGlenn/inject-template.svg?theme=shields.io
[daviddm-url]: https://david-dm.org/VandeurenGlenn/inject-template
[coveralls-image]: https://coveralls.io/repos/VandeurenGlenn/inject-template/badge.svg
[coveralls-url]: https://coveralls.io/r/VandeurenGlenn/inject-template

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