Creating your own template engine in JavaScript: part 1

Monday, March 5, 2012 Posted by Ruslan Matveev 6 comments
Today I'm going to tell you how to create your own template engine in JavaScript. The question is why? There are dozens of template engines already available so why do we need to create another one? This is the list of my reasons:

  • - There are many template engines but most of them are built with no API to extend it (so you cannot add your own function, your own constructions and so on...)
  • - There are JavaScript template engines that compile your template into plain JavaScript, on one hand it's good, but on the other hand - we cannot reuse (port) this code to other languages (for example Java), so I've decided to make it easily portable.
  • - I used to use Smarty template engine for PHP, so I wanted to make my template engine syntax look close to it.