41 ms·
On Using a Templating Language with PHP
- cweagans 12y agoBig debate? Use what works for you. I prefer using Twig because it enforces not shoving random PHP into your templates, and there's no performance hit for using it (since it's compiled back to PHP).
- towelguy 12y agoI really like the twig template engine [0]. It will compile your template back to PHP code so it will run as fast as if you used PHP directly. [0]http://twig.sensiolabs.org/ http://twig.sensiolabs.org/
- krapp 12y agoIf you're going to use a templating language on top of PHP, IMHO, just use Twig. As already mentioned, it compiles templates back into PHP. But, you also get automatic escaping (with various contexts, such as escaping for html and escaping for js), hooks to the lexer to write your own tags, filters and extensions, a function sandbox, and if you're using an older version of PHP, you can use js-style array and object shorthand ( [] instead of array() and {key:value} ) in the templates themselves. It is almost a framework implemented in its own (arguably stricter and saner) language in and of itself. Obviously, you can get by without a templating framework. But I find that if you do, you're either going to have to reimplement features that already exist in them (in particular, an escaping strategy), or else suffer the consequences if you don't get it perfect.