Skip to content

Pinjasaur/templater.js

Repository files navigation

templater.js

Build Status GitHub License

Dead-simple JavaScript templating with a tiny1 footprint. View the website for extended details & documentation.

Inspired by http://jsforallof.us/2014/12/01/the-anatomy-of-a-simple-templating-engine/ and http://krasimirtsonev.com/blog/article/Javascript-template-engine-in-just-20-line.

1 < 1KB minified + gzipped.

Quick Start

  1. Install the script

    The script can be installed with Bower, npm, or by grabbing the latest release from GitHub.

    bower install templaterjs # For Bower
    npm install templater.js # For npm
  2. Load in the script

    If in a browser environment, with a <script> tag

    <script src="path/to/templater.min.js"></script>

    Or, if in a Node.js environment with a require()

    var templater = require("templater.js");
  3. Create the template

    <!-- by giving it a non-standard `type` the browser will ignore it -->
    <script id="template" type="text/template">
    <h1>Hi, I'm {{name}}.</h1>
    </script>
  4. Use template and render it against some data

    var template = templater(document.getElementById("template").innerHTML),
        context = {
          name: "Paul"
        };
    
    console.log(template(context)); // <h1>Hi, I'm Paul.</h1>

Documentation

For further documentation and resources, visit the templater.js website.

Contributing

If you'd like to fork the repo and submit pull request, please feel free.

Check out CONTRIBUTING.md for specifics.