PHP is not a template engine, but a language that can be used to write templates or template engines. The template engine is not only a language, but also a programming API that allows scripts to find, organize templates, or assign data to them from a script. Pure PHP offers you absolutely nothing - it's just a language. Instead, you should take libraries such as Zend_View in the Zend Framework for comparison (basically, it works just like Smarty, except that it uses PHP to write templates). You should ask if you should use the template engine with PHP or something else as a template language.
When it comes to the templates of the languages ​​themselves, then it’s good ... normal loops and conditions are enough to write templates, but this “enough” does not mean that it is easy, convenient, efficient or flexible. PHP does not offer anything special for template designers, but many "template languages" (like Smarty) provide only a limited subset of PHP, so I'm not surprised that programmers choose PHP. At least they can write functions and use OOP, which are too large for this (in my opinion), but really help and really help.
The fact is that custom template languages ​​are not limited by the disadvantages of PHP, but their designers do not see it, claiming that "displaying variables and a loop is enough." Possible areas where template languages ​​can be much more efficient:
- Display and rendering of forms (I did not see any frameworks with PHP as a template language, which provided an easy, flexible and universal system for adjusting the appearance of the form).
- Understanding the structure of an HTML / XML document.
- Automatic filters for injection XSS.
- Solving various common problems at the presentation level (for example, customizing the appearance of the paging system, displaying data in columns, etc.).
- Template portability and true separation of application logic and implementation details from templates.
Examples of language templates that follow this method are mentioned above by PHPTAL and Open Power Template 2. Some similar ideas can also be found in TinyButStrong, but unfortunately this template engine is very slow.
Zyx Jul 10 '09 at 16:40 2009-07-10 16:40
source share