Moteur de templates
Depuis la version 6.0.0 d'Ovidentia un nouveau moteur de templates optionnel a été intégré. Il n'est pour l'instant disponible qu'à des fin de tests mais pourrait remplacer le moteur actuel dans une future version d'Ovidentia.
Sommaire
Activation
Pour activer le nouveau moteur de template il faut ajouter la ligne suivante dans le fichier config.php :
$babUseNewTemplateParser = true;
Compatibilité
Le nouveau moteur de templates à été développé de manière à pouvoir remplacer le moteur actuel de façon transparente : les templates existants produisent les mêmes résultats avec les deux moteurs.
Il existe cependant certains points qui ne fonctionneront pas comme précédemment avec le nouveau moteur :
- Les accolades imbriquées dans d'autres accolades ne seront pas remplacées (par exemple
{ myVar{ myNumber } }) - Les accolades contenues dans la valeur d'une variable de template ne seront pas remplacées
Note that the new functionalities introduced (see below) will not be backported to the legacy engine and so, templates using them will not be compatible with the current engine.
Performance
The main goal of the new engine is to improve the overall performance of template parsing. Speed improvements have been achieved through several techniques.
New pipeline
The templates are now processed in two steps: the template is first compiled into php code which in turn is executed to generate the html.
parse to php execute php
[my_template.html] ==================> [php code] ==============> [html]
Caching
The intermediate php code can be cached so that if a template is accessed several times on the same page, parsing is done only once.
available in cache ? execute php
|========================> [cache php code] ==============> [html]
| ^
| |
| | store in cache
| |
| parse to php |
[my_template.html] ==================> [php code]
Benchmarks
Aucun benchmark pour l'instant.
New functionalities
Filters
It is now possible to apply filters on template variables (i.e. variables in curly braces { }) before they are replaced. The following syntax { myVar:filter } means that the filter named filter will be applied the content of myVar when it is replaced. For the time being, the following filters are the available:
- html
- html special characters are replaced by the corresponding html entities
- htmlall
- ...
- js
- ...
Debugging
One new interesting functionality for developers is the possibility to debug templates.