Do Not Use PHP Template Engines. (Twig, Smarty, Blade)

preview_player
Показать описание
Template Engines are obsolete. Who needs them anyway? With HTML5 and JS, you do not need to learn a third 'maybe' language.
Рекомендации по теме
Комментарии
Автор

Backend rendering is still the best solution for rendering content based website especially for SEO.

Omeostatica
Автор

I couldn’t stop looking at your books on the shelf, about to fall right any moment

mescalinum
Автор

I love twig its so easy to learn and saves many hours of labor.

jaygreentree
Автор

Template Engines are simply another abstraction layer.
When using a proper IDE and plugins you can speed up development time using template engines very well.
I dont take your advice, as it's like saying do not write OOP PHP, you can do everything in functions. That is as well another abstraction layer to separate code. Therefor a template engine does as well clean up your code and makes everything more readable.

Sidenote: I dont use template engines.

vagabund
Автор

Templating engines make your code easy to maintain and reuse. Any performance benefits you might get by not using them will be minimal or insignificant and heavily outweighed by the benefits of using a template engine.

For example, blade essentially has zero overhead with the templates being complied into plain php code and cached until you edit them again. Basically, it's your loss if you don't use them.

william
Автор

Was Du sagst hat bestand! Wenn ich es richtig verstanden habe den Html Code direct in der Ausgabe von PHP zu integrieren. Ja das Rendering in Framworks ist ein Lebenszeit-Räuber ;)

IK-vfjs
Автор

I have never used a templating engine. PHP is a templating language and for presentation of dynamic data, it does it too well. I know there are reasons for using templating engines but PHP works fine.
My codebase is properly structured with the MVC approach to use the minimum required PHP for presentation of the front-end view data.

chibuzorisrael
Автор

Hi, i do agree. After many tries with heavy template engines, i've finally decided to code mine using only pure PHP. The engine runs in just one class and has no other syntax to learn. It's called PhpEcho. Give it a try and tell me. Anyway thanks for the explanation

rawsrc
Автор

Hmm. I think template engines can be good, because it restricts developers from putting backend logic into frontend which keeps your project more clean. Yes you can do some if statements and loop stuff in template engines, but it doesn't go any further than that.

emielschumacher
Автор

"Just use <?= ..."
This video has 8k views so far. I wonder how many people took your advice and built websites with XSS vulnerabilities. The main advantage of templating engines is that they HTML-escape all output by default. This alone should be enough reason to use them.

hbgl
Автор

I'm a web developer and use PHP daily, template engines weren't designed for us. I include twig in most of my sites so that the designer and users can customize their sites without having to learn PHP.

billyz
Автор

i cant give a thumb to this video. biggets reason is that, most frameworks use template engines to better the code and make developer less writing as not to mix too much backend to the front part. if u tell us not to use it ! thus awkward. it may some jeolus or anyelse but twig and blade are my fave.

tmaddy
Автор

I had the same oppinion 10 years ago, but since then i have changed my mind. Mainly because of:
1. Requests to webserver should never go past CDN after first request to same url, so there are no overhead in having separate template libraries. This can very easily also be pre-cached.
2. One can argue it breaks SOLID design patterns to mix response and request logic or presentation layer and business logic.
3. Its easier for a human brain to see small pieces of code and allows to focus on the real job.
4. Why reinvent the wheel? There always comes a set of functions related to only php templates that very likley will be quick-hacks that can be avoided by using a template language that is properly maintained. Examples are to override either your own or others views in third party applications.
5. Its easier for code quality control tools to analyze the code if its split up so html can be analyzed separatley and php separatley. Also IDE support, especially with autocompletion is often much more easy to configure when using plain php.

patrikabc
Автор

A better title for this video would be "Why I do not use PHP Template Engines". Although I technically agree that you can do the job with PHP itself, I am using for example Twig to take away the hassle of programming all the bits and pieces in PHP, where I can keep the HTML kind of layout in tact with Twig and exchange some literals with variables and add a loop here and there.
This is a very simplistic presentation of how to use Twig, but I think you get the point. On the complexity and what you do with Twig is part of the design. If you put a lot of logic in Twig than I think you are doing something wrong. A bit like, if you need a lot of jQuery to put your HTML straight, you are also doing something wrong.

Although I have the skills to put all the templating in PHP itself, I can't imagine see me doing it. So I keep on using Twig (or Blade or Smarty whenever a customer requires this).

johannesvandemerwe
Автор

Do you have a video giving an example of what the correct way would be?

TiagoCaus
Автор

template engines will save a lot of development time.... template engine will generate php version.... in production, it will only render generated version... which is in real php code... u should compare its benchmark first....

elmyrockers
Автор

How about a case when I need to allow CMS user to use templating engine in text editor. You think that allowing PHP code in text is a good idea?

zledwon
Автор

i think your statement is a little broader than you present. Your argument suggests not to use views in the back end. not just template engines, not just php. i could agree with that statement, it's what i prefer anyways but how about emails. I still find it very useful to utilize blade for email templates and i sure as hell cannot use vue js on client side in that case. I don't like using php as a template engine because it's a lot less readable and either i'll need to cache my views anyway or i have so much time that the bulkiness won't bother me.

timucinbahsi
Автор

I don't agree with what you say. A template engine set limit functionalities to front developer.
If you let the front developer use PHP, he can do things that he shouldn't be able to do.

shandercage
Автор

I totally agree. PHP gives you much more options than any template engine. Excellent point Lionel. Keep up the good work!

fabianotaka