4 ms·
I've been using PHP for most of my life, and used various template engine and it always end up with one question : what is the real purpose of a template engine
by mamadrood 10y ago
I've been using PHP for most of my life, and used various template engine and it always end up with one question : what is the real purpose of a template engine in PHP instead of just using PHP ? When I see the examples in twig homepage it just looks like they tried to make PHP examples verbose for the sake of it.
I don't really mind them, but I find it extremely boring to have to register in the template engine every function that you will end up using somewhere else in your code and eventually have a language with less feature than plain old PHP and an other layer of cache.
So which use cases make you need Twig, for instance ?
- TheOneTrueKyle 10y agoWorking with designers who just want to make a few changes. All that PHP can be intimidating, but basic templating is doable.
- CiPHPerCoder 10y agoIf you have a designer who's worked with templating engines in other languages (e.g. Django/Python projects), they already know what they're doing. It also makes it easier to separate your presentation logic from your business logic. For example: https://github.com/paragonie/airship/blob/master/src/Cabin/Bridge/Lens/cargo/bridge_perms_context.twig https://github.com/paragonie/airship/blob/master/src/Cabin/B... This uses macros and other fun things. Doing that in PHP would get messy. https://github.com/paragonie/airship/blob/master/src/Cabin/Bridge/Lens/macros/permtable.twig https://github.com/paragonie/airship/blob/master/src/Cabin/B...
- mamadrood 10y agoOkay, I've never worked with a designer that would touch code, so there is that. Macros seem a bit redundant with partial views in my opinion, except they take fixed parameters, but this is a interesting concept.