- This topic has 20 replies, 1 voice, and was last updated 2 months, 1 week ago by o_daan.
- November 15, 2020 at 1:54 am #2314Mc_UsernameTakenParticipant
I DO NOT like template engines, such as: twig, smarty or blade, and don’t want anything to do with them.
I’m searching for a decent/good framework like Laravel, that is intuitive to use and scales well for larger projects, 10.000 – 20.000 users average, something that doesn’t turn into »pasta bolognese« the second another developer enters the project.
I am comfortable educating other people and telling other developers to abide by certain standards, but it still sets some requirements for/by the codebase.
Can someone recommend something that is worth looking into? some without a template engine.Or maybe even a good CMS, like Drupal7 was (if only they hadn’t enterprisefied it in D8)
I’m very picky and specific, I know that, in what I decide to work with, which I why i’m looking for recommendations on this matter 🙂 I can’t be the only one who thinks this.November 15, 2020 at 1:54 am #2315phptipsGuest
If anyone other than yourself will ever work on this code, please don’t do this.
It’s sort of like trying to pound in a screw with a hammer instead of using a screw driver.
>something that doesn’t turn into »pasta bolognese« the second another developer enters the project.
That’s exactly where you’re headed if you don’t use a template engine.November 15, 2020 at 1:54 am #2316hparadizGuest
Yea unfortunately any attempt at not using templates ends up creating patterns that eventually turn into you re-inventing the wheel yourself. You’ll end up re-implementing concepts like template inheritance without even realizing it. Template engines are really fast. I use them in production on some very serious projects and the template engine adds barely a millisecond to the pageload. Your concerns are from a lack of understanding.
I used to write my code the way you want but after learning a lot I don’t anymore.
Code actually comes off cleaner when you use a template engine. Especially when you have multiple developers. And especially when you have designers working on the HTML that should not be anywhere near a PHP file.
I highly recommend you learn Twig and use it if you want to stay employable.November 15, 2020 at 1:54 am #2317colshrapnelGuest
any framework is just a set of packages. you can always configure your own set
that said, this question just screams of the Dunning-Kruger effectNovember 15, 2020 at 1:54 am #2318CrellGuest
Statistically speaking, your odds of producing an injection-based security hole when using plain PHP templating on a serious project are *does math* 100%.
This could be a good learning experience for you, but the odds of you not screwing up are extremely remote, assuming you’re a human. Lots of other people in the thread are arguing about code structure and organization and inheritance but… really, security. You’re 100% on your own (and your other devs’ own) to remember to properly and contextually escape *every* value you output. Someone on the project is going to get that wrong. A lot. And every one will be a security hole.
Please don’t do that to your customers/users.November 15, 2020 at 1:54 am #2319MattBDGuest
I wouldn’t recommend this approach, as from personal experience I know that using PHP for templating makes it too easy to put too much logic in the view layer. I currently maintain a legacy Zend project and there’s too many cases where logic got dumped in the view layer that doesn’t belong there.
You might consider Plates, which while it is a templating system, doesn’t use any new syntax, but will give you a sophisticated inheritance system.
Regarding frameworks, have you looked at [Mezzio](https://docs.mezzio.dev/mezzio/), formerly Zend Expressive? It allows you to choose whatever template layer you like from Twig, Plates, and laminas-view native PHP.November 15, 2020 at 1:54 am #2320welcomatticGuest
You can install and use Symfony without Twig at all. Since 4.0 Symfony can be installed without any component, which means that you can install only needed component. If you do not want Twig, do not install it. [https://symfony.com/doc/current/setup.html#creating-symfony-applications](https://symfony.com/doc/current/setup.html#creating-symfony-applications) use `composer create-project symfony/skeleton my_project_name` commandNovember 15, 2020 at 1:54 am #2321sproingieGuest
Anyone who thinks Drupal 7 was a good way to write code should be in a padded cell.November 15, 2020 at 1:54 am #2322rupertjGuest
>Or maybe even a good CMS, like Drupal7 was (if only they hadn’t enterprisefied it in D8)
D8 is basically what you’d get if you re-wrote D7 as a Symfony app, so if you don’t like that about D8, you’re not really going to get along with the “decent/good framework” you desire.November 15, 2020 at 1:54 am #2323ssnepentheGuest
Unless something has changed recently, Laravel supports plain php template files out of the box… Just replace the “.blade.php” extension with a “.php” extension.
Or use a less opinionated framework like slim and bring your own “templating” system (for example [slimphp/PHP-View](https://github.com/slimphp/PHP-View)).
Or there is always [Plates](https://github.com/thephpleague/plates/) which exists somewhere in between plain php and a templating engine.
Just don’t forget that you lose automatic escaping so make sure you are handling it manually as appropriate.November 15, 2020 at 1:54 am #2324dotioguyGuest
You can use Laravel without blade. Simply name your views *.php instead of *.blade.php and you are set!November 15, 2020 at 1:54 am #2325steenbagGuest
Lumen is a microframework based on Laravel and is primarily geared towards API/microservice development. It doens’t include a template engine built-in, but because it Laravel-based you can add in any of the missing components as needed.November 15, 2020 at 1:54 am #2326slepicoidGuest
htmlspecialchars all over the place, yaikes! I can bet it gets forgotten somewhere and smile is growing under XSS attackers’ noses.November 15, 2020 at 1:54 am #2327wackmaniacGuest
Unless you application is solely an API a some form of templating will prevent building output inside your business logic. If you’re as picky as you claim to be I can only assume you’re also picky about things as separation of concerns. Which would imply some form of templating is desired.
Is it an option to inject your own implementation of a template engine into an existing framework? One might assume that any decent/good framework depends on interfaces rather than implementations. Inject your own implementation of that interface that does nothing but include a PHP file. No template engine, but maybe still a little bit 🙂
I’m not very familiar with the majority of frameworks that are available at this moment, but I once replaced Twig with Smarty in a Symfony installation, so at least in Symfony it is (or was) possible to replace Twig with another template engine. A nasty side effect of this approach was that Symfony basically has a vendor lock-in with Twig as the majority of Symfony bundles that generate some form of output expects Twig to be used as template engine. As a result you will either still need to include Twig, rebuild templates – if possible – or not depend on off-the-shelf bundles.November 15, 2020 at 1:54 am #2328MicrowaveLoverGuest
No template engine? Only way I can think it’s possible is either using static html or some kind of WYSIWYG editor. Or using a framework without templating engine and putting it in yourself, though that seems pointless in most cases.
If your code turns into pasta when other developer enters that means you didn’t set standards or rules for the code, don’t do enough of code reviews or your own code doesn’t follow any rules or good practices. Use linters and other tools for that, use automatic tests to check all of those things.
- You must be logged in to reply to this topic.