mirror of
https://github.com/codeguy/php-the-right-way.git
synced 2025-08-22 13:13:05 +02:00
syntax highlighting for Twig examples enabled
This commit is contained in:
@@ -1,24 +1,22 @@
|
||||
---
|
||||
isChild: true
|
||||
anchor: compiled_templates
|
||||
anchor: compiled_templates
|
||||
---
|
||||
|
||||
## Compiled Templates {#compiled_templates}
|
||||
## Compiled Templates {#compiled_templates_title}
|
||||
|
||||
While PHP has evolved into a mature, object oriented language, it
|
||||
[hasn't improved much](http://fabien.potencier.org/article/34/templating-engines-in-php) as a templating language.
|
||||
Compiled templates, like [Twig](http://twig.sensiolabs.org/) or [Smarty](http://www.smarty.net/)*, fill this void by
|
||||
offering a new syntax that has been geared specifically to templating. From automatic escaping, to inheritance and
|
||||
simplified control structures, compiled templates are designed to be easier to write, cleaner to read and safer to use.
|
||||
Compiled templates can even be shared across different languages, [Mustache](http://mustache.github.io/) being a good
|
||||
example of this. Since these templates must be compiled there is a slight performance hit, however this is very minimal
|
||||
when proper caching is used.
|
||||
While PHP has evolved into a mature, object oriented language, it [hasn't improved much][article_templating_engines] as
|
||||
a templating language. Compiled templates, like [Twig] or [Smarty]*, fill this void by offering a new syntax that has
|
||||
been geared specifically to templating. From automatic escaping, to inheritance and simplified control structures,
|
||||
compiled templates are designed to be easier to write, cleaner to read and safer to use. Compiled templates can even be
|
||||
shared across different languages, [Mustache] being a good example of this. Since these templates must be compiled
|
||||
there is a slight performance hit, however this is very minimal when proper caching is used.
|
||||
|
||||
**While Smarty offers automatic escaping, this feature is NOT enabled by default.*
|
||||
|
||||
### Simple example of a compiled template
|
||||
|
||||
Using the [Twig](http://twig.sensiolabs.org/) library.
|
||||
Using the [Twig] library.
|
||||
|
||||
{% highlight html+jinja %}
|
||||
{% raw %}
|
||||
@@ -33,7 +31,7 @@ Using the [Twig](http://twig.sensiolabs.org/) library.
|
||||
|
||||
### Example of compiled templates using inheritance
|
||||
|
||||
Using the [Twig](http://twig.sensiolabs.org/) library.
|
||||
Using the [Twig] library.
|
||||
|
||||
{% highlight html+jinja %}
|
||||
{% raw %}
|
||||
@@ -67,3 +65,9 @@ Using the [Twig](http://twig.sensiolabs.org/) library.
|
||||
{% endblock %}
|
||||
{% endraw %}
|
||||
{% endhighlight %}
|
||||
|
||||
|
||||
[article_templating_engines]: http://fabien.potencier.org/article/34/templating-engines-in-php
|
||||
[Twig]: http://twig.sensiolabs.org/
|
||||
[Smarty]: http://www.smarty.net/
|
||||
[Mustache]: http://mustache.github.io/
|
||||
|
Reference in New Issue
Block a user