what are the benefits of using a template engine

temuri picture temuri · Jul 22, 2013 · Viewed 11.6k times · Source

I do not understand why a developer would use Phalcon's Volt template engine.

In the end, after the compilation, the same PHP files are produced, that I would have to write manually in the first place. To me, it looks only to be detrimental to the performance.

Is the answer "so you could pass .volt files to a front-end guy"?

Answer

Nikolaos Dimopoulos picture Nikolaos Dimopoulos · Jul 22, 2013

The answer lies in the development of your application. Why do you use a framework instead of pure PHP? Why bother with object oriented programming when procedural/straight PHP is faster?

There are many reasons of course and it is a long discussion. The summary is ease of use and maintainability.

The same goes with Volt. You can use the volt templates to do what it will take you a lot longer if creating plain phtml files (HTML with PHP tags in there). Examples I can give you are template inheritance, partials, calculations within the template (for/each loops) etc.

As far as performance is concerned, there is always a performance hit when using a template engine. Volt luckily is part of Phalcon so the performance hit is minimal since Phalcon does all the hard work in memory instead of using included files here and there to offer its functionality.

The decision is up to you. Volt, Smarty, Twig and others are there to help with development of your application. Your decision is what makes you use the template engine or not.