3 ms·
Yes, but if you're using short tags, things can be better ;) <? if($foo) { ?> <b><?= $bar ?></b> <? } ?> True, it's not as nice as a templating langua
by Udo 13y ago
Yes, but if you're using short tags, things can be better ;)
<? if($foo) { ?>
<b><?= $bar ?></b>
<? } ?>
True, it's not as nice as a templating language, but then again, it doesn't have the aforementioned limitations either. Inlining views is a choice, it tend to avoid this. Just because templating engines prevent this pattern doesn't mean you'll be forced to use it in plain PHP.
Re-interpreting templates is also an interesting case. Of course, native templates will pretty much always be faster so the need to cache isn't as pressing. But still, with the built-in output buffer functions it's easy to do something like
do_some_caching(function() {
include('sometemplate');
});
- krapp 13y agoI was playing around with Slim framework recently and I 'discovered' the option in the PDO driver to fetch into a class. Add a parent class to the data classes (with magic setters and getters, having the getter wrap everything in htmlspecialchars)[1] and you really can, probably, accomplish most of what a lot of templating systems do (and a good chunk of MVC with the serial numbers filed off) with a fraction of the code in most frameworks and, say, Twig. Even static caching probably, using output buffering. [1]http://stackoverflow.com/questions/8898794/using-pdofetch-class-with-magic-methods http://stackoverflow.com/questions/8898794/using-pdofetch-cl...