@rexfng/tpl
v1.1.4
Published
A template engine to inject scripts or stylesheet into the dom
Downloads
5
Readme
Tpl
Description
Tpl provides helpers that append html node to a html file.
Options
| Options | Type | Description | Example
|---------------|-------------|-------------|----------|
|dom|String|The option dom takes in a string of already rendered html string|<html></html>|
|head|Array of Strings|Strings to be inserted in the tag if it is unfound from "dom", will be appended. They will be appended in the order of the array.|["<script></script>", "<style></style>"]|
|bottom|Array of Strings|Strings to be inserted in the end of |["<script></script>", "<style></style>"]|
Usage
const Template = require('@rexfng/tpl')
let tpl = Template.init({
dom: Mustache.render("<html><head><style>h2{color:brown;}</style></head><h2 class='title'>{{title}}</h2> spends {{calc}}</html>", view),
head: [
'<style>h2{color:red;}</style>'
],
bottom: [
'<script>alert("script appended 1!");</script>',
'<script>alert("script appended 2!");</script>',
'<script>alert("script appended 3!");</script>'
]
})
//can be use in express or http
res.set('Content-Type', 'text/html');
res.send(tpl) 