# Templish A templating language for JavaScript, using JavaScript. ## Installation Install with NPM: npm install --save templish ## Usage A simple example: ``` JavaScript //First, require the library var Templish = require("templish"); //Create a templish template var t = new Templish("{{conf.title}}", ["conf"]); //Create an environment var env = { conf: { title: "Hello, World!" } } //Execute the template t.exec(env, function(err, res) { console.log(res); //Hello, World! }); //Execute the template again, this time with a different environment env = { conf: { title: "Good Morning, Earth!" } } t.exec(env, function(err, res) { console.log(res); //Good Morning, Earth! }); ``` We can do more complex things, even with asynchronous functions: ``` JavaScript var fs = require("fs"); var Templish = require("templish"); //Create a templish template var t = new Templish( "{{fs.readFile('someFile', 'UTF8', cb)}}", ["fs"] ); //Create an environment, this time with the `fs` method to let us access files var env = { fs: fs } //Execute the template t.exec(env, function(err, res) { console.log(res); //If we assume the `someFile` file contains "hi, world": //hi, world }); ``` We can have multiple statements: ``` JavaScript var Templish = require("templish"); //Create a templish template var t = new Templish("\ {{ \ var str = 'Hello World'; \ return str; \ }}", [] ); //Execute the template t.exec({}, function(err, res) { console.log(res) //Hello World }); ``` Notice that with multiple statements, you have to include the `return` statement yourself. Of course, in practice, you would probably want your templates to be individual files, and not inline in the script file, not that Templish cares, as long as it receives a string.