Add new Templating section.

This commit is contained in:
Jonathan Reinink
2014-07-25 14:53:02 -04:00
parent 89e79368e8
commit b761690292
35 changed files with 118 additions and 2 deletions

View File

@@ -0,0 +1,28 @@
---
isChild: true
anchor: plain_php_templates
---
## Plain PHP Templates {#plain_php_templates_title}
Plain PHP templates are simply templates that use native PHP code. They are a natural choice since PHP is actually a
template language itself. That simply means that you can combine PHP code within other code, like HTML. This is
beneficial to PHP developers as there is no new syntax to learn, they know the functions available to them, and their
code editors already have PHP syntax highlighting and auto-completion built-in. Further, plain PHP templates tend to be
very fast as no compiling stage is required.
Every modern PHP framework employs some kind of template system, most of which use plain PHP by default. Outside of
frameworks, libraries like [Plates](http://platesphp.com/) or [Aura.View](https://github.com/auraphp/Aura.View) make
working with plain PHP templates easier by offering modern template functionality such as inheritance, layouts and
extensions.
Example of a plain PHP template (using the [Plates](http://platesphp.com/) library):
{% highlight php %}
<?php $this->insert('header', ['title' => 'User Profile']) ?>
<h1>User Profile</h1>
<p>Hello, <?=$this->escape($name)?></p>
<?php $this->insert('footer') ?>
{% endhighlight %}