How to write a template compiler in JavaScript

added by bpwndaddy
9/3/2015 1:30:09 AM

700 Views

Templating is a huge part of web services. It allows developers to express values from inside their markup (HTML) and have them show up in the output. Templates are valuable because, servers can respond with data based upon the request itself, instead of just using static HTML files. EJS stands for Embedded JavaScript, and is kind of like PHP-style templates in JavaScript. An EJS evaluation, surrounded in , allows for any JavaScript expression, but only evaluates it. An EJS expression, surrounded in , is also JavaScript, and prints out the evaluated result. Here is an example of EJS templates in use: We want to turn any given EJS template into a function, so we can use it to output HTML from our server. How can this be done?


0 comments