syntax highlighting for Twig examples enabled

This commit is contained in:
Peter Kokot
2014-12-11 11:30:15 +01:00
79 changed files with 1439 additions and 1091 deletions

View File

@@ -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/