1.1.0 • Published 2 years ago

nodetmp v1.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

nodetmp

An alternative to ejs.

Installation

npm i nodetmp

Usage

import { compile } from "nodetmp";

const output = compile(pathOfInputFile, dataObje);

console.log(output.output); // compiled output

output.write(pathForOutput); // write file at given location

template

{:if condtion}
<!-- if body -->
{:else}
<!-- else body -->
{/if} 
{:each array as item,id}
<!-- body -->
{/each}

As middleware

import {html_renderer} from "nodetmp";

app.use(html_renderer);

then we can use "res.html" function to parse html file.

// first argument -> path of html file relative to root folder
// second argument -> data which need to be  passed 
app.get("/", (req, res) => res.html("/index.html", {count:0}))
// index.html

<h1> {count} </h1>

there is also a "include" function available to include another html file.

// counter.html

<h1> {count} </h1>


// index.html

// one argument -> path relative to root folder
<div> 
    {include("/counter.html")}
</div>

License

MIT

1.1.0

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago