🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

inject-template

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

inject-template

Inject template into innerHTML

1.1.0
latest
Source
npm
Version published
Weekly downloads
12
20%
Maintainers
1
Weekly downloads
 
Created
Source

inject-template NPM version Build Status Dependency Status Coverage percentage

Inject template into innerHTML

Installation

$ npm install --save inject-template

Usage

  • An template tag in the desired element 1
  • An html template 2
var injectTemplate = require('inject-template');

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

result

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

rainbow.js 1

class Rainbow extends HTMLElement {
  constructor() {
    super();
    // @template rainbow
  }
  ...
}

rainbow.html 2

<template>
  BIG RAINBOW
</template>

Named templates

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

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

Custom templates path

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
Default: null

Path to file containing the template tag

templatePath

Type: string
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
Default: null

The content of the element (used in 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

Keywords

inject

FAQs

Package last updated on 07 Apr 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts