Introduction
Below is an easy way to create Templates in JavaScript files without changing your code format.
Background
I needed an easy way to keep my HTML clean and formated properly, when added to JavaScript files. So I came up with the following solution that seems to work well.
Using the code
All you need is the function below to keep your code clean.
function template(t) { return t.toString().replace(/^[^\/]+\/\*!?/, '').replace(/\*\/[^\/]+$/, ''); }
Easy JS Templates
To create nice looking, easy to read, easy to manage templates, follow the examples below. You won't have to worry about single or double quotes terminating your strings. Post between /*!
and */
and everything should work fine.
var html = template(function() {});
var css = template(function() {});