Please explain what a template engine is, and what it is used for. What are the paragraphs below trying to say? I don’t follow the author’s explanation.
Although CodeIgniter does come with a simple template parser that can
be optionally used, it does not force you to use one. Template engines
simply can not match the performance of native PHP, and the syntax
that must be learned to use a template engine is usually only
marginally easier than learning the basics of PHP. Consider this block
of PHP code:<ul> <?php foreach ($addressbook as $name):?> <li><?=$name?></li> <?php endforeach; ?> </ul>Contrast this with the pseudo-code used by a template engine:
<ul> {foreach from=$addressbook item="name"} <li>{$name}</li> {/foreach} </ul>Yes, the template engine example is a bit cleaner, but it comes at the
price of performance, as the pseudo-code must be converted back into
PHP to run. Since one of our goals is maximum performance, we opted to
not require the use of a template engine.
A template engine is simply a way to embed your back-end code into your html. This is more common in languages like Python and Ruby than PHP since PHP already supports embedding within html code.
That specific templating engine may be easier for those coming from other back-end languages, particularly Python or Ruby since Django and Rails have very similar-looking syntax for templates.
While not necessarily a “template engine”, I typically organize my Codeigniter projects where I have a template.php view that contains the skeleton layout and the content of each page of the site/application is a separate view that is loaded within the template.php file. This way I am not rewriting code on each page.
Template engines are all about personal preference–they aren’t needed, but some people feel more comfortable using them if that’s what they are used to. And people are more effective the less they have to think about their workflow!