A template engine is a library or framework that separates logic from template files. These libraries provide their own syntaxes for passing necessary values to the template from the controllers or models. Once successfully implemented, we should only have simple if-else
statements and loops inside the template files and there shouldn't be any complex code.
There are plenty of open source template engines available for PHP. Smarty, Mustache, and Twig are some of the popular ones amongst them. Throughout this book, we will be using the Twig templates engine created by SensioLabs. If you are not familiar with template engines, I suggest you look at the Twig documentation at http://twig.sensiolabs.org/documentation.
Now let's get started by integrating Twig templates into WordPress. You can grab a copy of the Twig library from the GitHub account at https://github.com/fabpot/Twig. Once downloaded, extract the ZIP file and you will get a folder called Twig-master
. Now...