gettpl

A lightweight simple JS templating

Usage no npm install needed!

<script type="module">
  import gettpl from 'https://cdn.skypack.dev/gettpl';
</script>

README

getTpl

Small script that provides a very simple HTML template for your javascript projects.

Installation

On top of your javascript file :

import getTpl from 'gettpl';

Usage

  • The HTML template is in your HTML page (hidden) and contains variables to be replaced :
<script id="my_template_id" type="text/template">
    <span>
        {{ foo }}
    </span>
    <p>
        {{ foo2 }}
    </p>
</script>
  • In your javascript, call the template with its id and variables will be replaced via an object
getTpl({ 
    foo:'bar', 
    foo2:'bar2' 
}, 'my_template_id'); 

Returns:

<span>
    bar
</span>
<p>
    bar2
</p>