Template Engines – Hasitha Gamage
This document will explain what is the template engine and the benefits of using template engines. Also, It will introduce famous template engines and compare the features. Apart from that, this document will provide the sample implementations for apache free marker and mustache template engines.
This is a sample project, I was implemented to demonstrate template engine usabilities. https://github.com/hasithalakmal/template-engine-evaluation/. Check out the code from this repository and let’s start working on it.
A template engine enables us to use static template files in our application. At the runtime, the template engine replaces variables in a template file with the actual values. Then it transforms the template into an expected file format like HTML, CSS, JS, etc. We can use these template engines to build our email body, HTML file content, etc.
Usually, the template engines are a smarty and have better performance with compiled files, which is another caching layer for the web application. So with the template caching you can save time in rendering your template to the browser which will boost your website page speed.
Always we are trying to separate application layers. By using these template engines we can easily separate out the business logic and presentation layers. Also, we don’t need to mix two-three languages in the same file. As an example, we don’t need to write PHP, JAVA, C# codes inside the HTML files.
The most powerful part of the template engine is template inheritance. Most of the template inheritance allows us to build a base skeleton template that contains all the common elements of our site and defines blocks that child templates can override.
This is the feature comparison of famous template engines. It has extracted from Wikipedia.