title | isChild | anchor |
---|---|---|
Plain PHP Templates |
true |
plain_php_templates |
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 or Aura.View make working with plain PHP templates easier by offering modern template functionality such as inheritance, layouts and extensions.
Using the Plates library.
{% highlight php %}
insert('header', ['title' => 'User Profile']) ?>Hello, escape($name)?>
insert('footer') ?>{% endhighlight %}
Using the Plates library.
{% highlight php %}
<title></title> section('content')?> {% endhighlight %}{% highlight php %}
layout('template', ['title' => 'User Profile']) ?>Hello, escape($name)?>
{% endhighlight %}