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

Поделиться
HTML-код
  • Опубликовано: 19 окт 2020
  • Template Engines are obsolete. Who needs them anyway? With HTML5 and JS, you do not need to learn a third 'maybe' language.
  • НаукаНаука

Комментарии • 163

  • @Omeostatica
    @Omeostatica 3 года назад +23

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

    • @leonardwass8392
      @leonardwass8392 2 года назад

      That's a good point.

    • @airaction6423
      @airaction6423 2 года назад +1

      This does have nothing to do with PHP template engines

    • @tolgaa8127
      @tolgaa8127 Год назад +1

      @@airaction6423 google bots fails to read the javascript codes.

  • @mescalinum
    @mescalinum 5 месяцев назад +3

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

    • @macd7743
      @macd7743 2 месяца назад

      Irrelevant but hilarious 🤣

  • @jaygreentree4394
    @jaygreentree4394 Год назад +5

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

  • @kidando
    @kidando 2 года назад +2

    I just discovered your channel the other day and each time ibwatch a video things i know about php (from experience since 2007) is just validated. The simple truth is that many non-php devs and beginner php devs have no clue how php works and especially how it all started. I appreciate you and your content

    • @lionelthetechlead8839
      @lionelthetechlead8839  2 года назад +2

      Thanks! I just hate it when they hate on something they don't know. Welcome on board team PHP.

  • @william254
    @william254 2 года назад +15

    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.

    • @TheInimicus
      @TheInimicus 2 года назад +1

      But what's the point? If you separete your view from your logic, you're going to include simple variables into the view anyway. Why would I use blade, if I can use use PHP template system like the guy in the video said? What's the adventage?

    • @william254
      @william254 2 года назад +4

      @@TheInimicus Blade is much easier to use, has cleaner code, automatically escapes, and is much easier reuse. Let me ask, why don't you use blade?

    • @TheInimicus
      @TheInimicus 2 года назад +1

      @@william254 In my opinion, if you render your view correctly; and in my opinion that means that the view only in fact has view logic in it; then blade and php-templates don't differ that much. Actually, in my applications the onlly difference would be

    • @william254
      @william254 2 года назад +4

      @@TheInimicus I think you're trying to argue that PHP templating is just as good as, e.g blade, and that by itself, should be a reason not to use blade.
      In my opinion, blade is better than php templating. Pretty much everything you mentioned that php templating can do, blade can do too, as well as adding some benefits on top.
      You can have logic-less views in blade, you can even write plain php if you don't want to use blade syntax. It offers you quite a bit of freedom.
      You argue that in promotes bad architecture with @if, but that's just the same with php templating. If someone adds @if on blade they just as likely to add *if* when templating with php.
      We can generally agree that blade is easier too, especially if you're just beginning. Blade is easier for both amateurs and experienced. The same can't be said about php templating.
      Cleaner code is just my opinion. I think loops and @if look better and are more readable, especially if there a designer in the team and they're are not familiar with php. The {{ $var }} is also easier to write.
      You make valid point about being able to switch a templating engine. But I also think that proper preparation should minimize the chance that you'll need. Besides, the need to change from php templating to a templating engine might occur too.
      If there were performance hits for using blade, then I'd seriously consider using php. But I don't think there are and even there are, they would likely be insignificant.

    • @TheInimicus
      @TheInimicus 2 года назад +1

      ​@@william254 I think you misunderstand me.
      I'm not saying "Don't ever use blade". Blade as a templating engine is fine. And I do agree, that it is slightly better than php-templating, it automatically escapes strings, has slightly cleaner syntax with {{, yes. If you compare just the CAPABILITIES of blade vs CAPABILITIES PHP, then blade is more capable than PHP, I agree.
      But!
      The cleaner your architecture becomes, the more blade and php-templating starts to look alike. In other words, the closer your application gets to having logicless-view, then more their source-codes will look alike. At the extreme, if you have view with 0 variables, 0 fors, 0 ifs, then blade and php-templating are the same file, exactly identical, wouldn't you agree? :) Plain HTML in both blade and PHP-template. (of course there's not many of such views, but I think you know what I mean - if the views are really simple, then blade and php source codes are very similar and their differences start to blend, you can't compare one against the other easily, if they're so similar). Of course, that's in well designed application. If your application has views for 3000 lines, of course blade will come on top, because it will stop you from doing stupid things, like accessing database in view; but that doesn't concern us, since we strive for well written application.
      So, the better your application, the adventages of blade start to disappear, as the application gets better and more mature.
      However, the cost of adding blade to your project (actually, any dependency for that matter) grows as the application develops. Ask any architect and they will tell you, adding libraries to your project is called "adding DEPENDENCIES" for a reason, if you add a dependency, your project starts to DEPEND on it.
      Examples of cost of dependencies:
      - if blade gets abandoned (won't be supported), we're screwed (that's what happened to faker library, for example). Yes, you can make a fork and maintain it yourself, but it's not easy and way more costly.
      - if there's a bug in blade, you can't fix it. Unless you fix it, and wait for the maintainer to include it, or you start maintaining it yourself
      - if there's a feature you use, that gets deprecated, you can't easily update blade, unless you update your code.
      - if there are two incompatible features in a library, and you want to use both of them at the same time, you're sqrewed.
      - if there are missing features in blade you need, you need to add custom logic to it - blade is actually pretty flexible, but other dependencies or other templating engines are not.
      - if you're customizing the engine, you can't really be sure if you don't break something
      - if there's a security error, but it gets fixed in the next version that's incompatbile with your current code base, you're screwed.
      - if blade and your application use a shared dependency (like maybe symphony polyfills) in different versions, you either try to get them to work; or downgrade blade (or try to upgrade, if it's compatible with your usage of it). if you can't downgrade or upgrade, you're sqrewed.
      - if blade uses an extension not supported by your PHP installation, you're sqrewed (maybe important on certain hostings)
      Please, keep in mind - that's not a list of reasons against blade, no! It's just a list of potential costs that might come with adding more dependencies. The list goes on, I just listed the most frequent one. The bigger your application gets, and the more dependencies you have, the more chance you'll come into one of them. So, to me, adding dependencies is a huge risk! Huge! And the adventages of blade that you listed just aren't worth it for me, only to have {{ instead of

  • @macronom
    @macronom Год назад +1

    What does your view look like? How does 'product' get into it, when the template is in an seperate file? You can not do this without some extra code in the view, right?

  • @HCforLife1
    @HCforLife1 3 года назад +1

    Do you thing it is good idea to go deep into JavaScript, Typescript React/Vue and NodeJS path in 2021?

    • @Snakes.StartToSing
      @Snakes.StartToSing 3 года назад

      Check the job market where you live , where I live, they are asking for angular, .net, django, php, node, typescript, aws, MySQL.

    • @lionelthetechlead8839
      @lionelthetechlead8839  3 года назад

      You're going to need JS regardless of the backend. I like Vue.js

  • @vagabund6778
    @vagabund6778 2 года назад +5

    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.

    • @lionelthetechlead8839
      @lionelthetechlead8839  2 года назад +1

      Why learn another abstraction layer when the first one is sufficient? That's like programming with python and php.

    • @btm1
      @btm1 2 года назад

      @@lionelthetechlead8839 because the learning curve is very small compared to the advantages they give...

  • @zledwon
    @zledwon 3 года назад +5

    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?

    • @lionelthetechlead8839
      @lionelthetechlead8839  3 года назад

      Depends. Will the user be allowed to use logic operation like if else and transformations? If its complex and can assure no hacking you can prob opt for a template engine. But if its just html i would just use str replace vars.

    • @zledwon
      @zledwon 3 года назад +4

      @@lionelthetechlead8839 So there is a scenario where you recommend using temp engines afterall :) Thus vid title is a bit missleading.

    • @lionelthetechlead8839
      @lionelthetechlead8839  3 года назад

      @@zledwon There's always tail edge cases. Like would you use angular if the client offered 100 Bitcoins. Going deeper into the issue. 1) would they need complex logic 2) would they know what variables to use, how the variable is structured 3) would they need more functionality with the power of PHP later on. At the end of the day, I might again recommend doing PHP files.

    • @cipi7640
      @cipi7640 2 года назад

      wordpress

    • @TheInimicus
      @TheInimicus 2 года назад

      That's really a different story and requires a separet topic.

  • @CoconutPete
    @CoconutPete Год назад +1

    I'm looking for a super simple way to make simple php web apps using the basics ...html,css,PHP, JavaScript without over complicating things..I come from the old school days of building websites with a text editor...any suggestions?

    • @lionelthetechlead8839
      @lionelthetechlead8839  Год назад +1

      I would suggest just learning the yii2 framework. It will cost you a week but you don't want to learn an something under powered and then have to re-learn something else and you want to do it in a scalable long term way.

    • @CoconutPete
      @CoconutPete Год назад

      @@lionelthetechlead8839 I'll take a look.. also interested in Vue.. there are so many options these days for languages, frameworks etc it is quite overwhelming... I still find php to be my favorite

    • @lionelthetechlead8839
      @lionelthetechlead8839  Год назад

      @@CoconutPete for a simple page, I would not recommend js, because of the async way that JS works makes things more complicated, you have to know what call backs and real time works like

  • @azzamqazi3766
    @azzamqazi3766 3 года назад

    Which framework to use then to organise the code and build applications on the MVC pattern?

    • @lionelthetechlead8839
      @lionelthetechlead8839  3 года назад

      Yii2 of course!

    • @thecodingworkshop4346
      @thecodingworkshop4346 3 года назад

      @@lionelthetechlead8839 so Yii2 doesn't use templating engine?. I've not used Yii2 so I don't know myself. And if not what does your view template looks like

  • @chibuzorisrael5878
    @chibuzorisrael5878 2 года назад +4

    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.

    • @lionelthetechlead8839
      @lionelthetechlead8839  2 года назад

      That's correct. Rasmus himself actually setup PHP as a templating language. But was confused when people started their own templating language on top of a templating language.

  • @emielschumacher3148
    @emielschumacher3148 3 года назад +20

    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.

    • @lionelthetechlead8839
      @lionelthetechlead8839  3 года назад +2

      Have you seen the logic with template engines. They've got for loops with conditional statements and event transformations. Don't forget you can still screw up your project with javascript.

    • @airaction6423
      @airaction6423 2 года назад +1

      Do you like restrictions? I like when I'm able to choose

    • @VitalijMik
      @VitalijMik 2 года назад +1

      @@airaction6423 yeah lets use PDO statements within my templates because i do not like restrctions. lets call every class a helper class and put it everywhere inside the template.
      With every template engine you can actually choose. per default everything is disabled and you add those features which are really required in your template. those features which are needed for your template

    • @lonelybiscuit243
      @lonelybiscuit243 2 года назад

      @@lionelthetechlead8839 yes but it gets rendered before it gets parsed in the request right? the user never gets any of the logic on his machine.

    • @TristanBailey
      @TristanBailey Год назад +1

      Display logic is not the same as putting app logic into the template. I would agree a template engine encourages to keep the separation as if you see plain php you can think again in where you put it.

  • @TiagoCaus
    @TiagoCaus Год назад

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

  • @patrikabc123
    @patrikabc123 2 года назад +6

    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.

    • @lionelthetechlead8839
      @lionelthetechlead8839  2 года назад +4

      just my 2c. 2) This is already handled by the PHP framework that does MVC. 3) Already handled by the framework. most view files in PHP are almost 80% html 4) These are not quick hack but might be extensive widgets. If not there's still javascript. 5) PHP has been around for 20 years so it's really well support. Again 90% of a view file is HTML.

    • @trefwoordpunk2225
      @trefwoordpunk2225 2 года назад

      Why reinvent the wheel? The inventor of the squared wheel used to chant this mantra to everyone...just think where we would be if people had listened!

    • @CottidaeSEA
      @CottidaeSEA 9 месяцев назад

      ​@@lionelthetechlead8839 You used 80% then 90% for the same statistic.
      One thing you forget is that these templating libraries can save you from XSS and simplifies things greatly.
      Before you go "but X framework solves that" I want to mention that not everyone uses one such framework, some might have their own minimal frameworks as well due to performance reasons, Symfony and Laravel aren't exactly speed demons with how much they do internally, so that simply means you've completely missed the point.
      Another reason to use something like Twig is that you don't have to go in and out of PHP context, you do not need to worry about some idiot using echo for HTML, you can limit the scope of what's possible, reducing the amount of possible footguns, etc.
      As for whether it's necessary to use something different, not really. But as a tech lead, you should also know that your responsibility is to ensure the developer team has a good toolset with as robust guardrails as possible in order to not break things.
      If you let someone do stupid shit, they will do stupid shit. If you haven't seen someone establish a database connection and fetch data in-between some HTML, then you clearly have lived a far too sheltered life, which is the only reason I could see you have these opinions.

  • @rawsrc
    @rawsrc Год назад +2

    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

  • @VitalijMik
    @VitalijMik 2 года назад +1

    Thank you for you Video, i want to add just 2 ct from my side. Yes Template engines are overloaded especiall twig or blade because you can even call classes within the template engine. But there are logicless template engines like Mustache/Handlebar.js which can be extended with logic but you have to it by yourself.
    But i would not say that you should stop using template engine for several reasons
    1) it is not true that you have just to replace {{ with

    • @lionelthetechlead8839
      @lionelthetechlead8839  2 года назад

      All you need to do is use a framework like Yii and it'll handle all the validation hard work. I think the only area where you maybe should use a template engine is where the user is designing the templates.

    • @VitalijMik
      @VitalijMik 2 года назад

      @@lionelthetechlead8839 this is not true, even Yii recommend on their Docs that you should use a template engine. Without a template engine there is a chance that a variable will not be escaped or code which does not belong into a template engine will land there.
      the reason where you might go well without a template engine is if you work alone without a team and you have years of experience and know what XSS is and you know what is View Logic and what is Controller Logic.

    • @lionelthetechlead8839
      @lionelthetechlead8839  2 года назад +3

      @@VitalijMik actually thats not entirely correct. Yii 1 did recommend a template engine because it was developed in the earlier versions of PHP. In yii2 PHP is the default template engine but it does allow the easy use of templating engines. Rasmus himself said he was surprised since PHP was already a templating language so he worked on other parts till 7 where the focus was on the embeded features that allow you to work PHP neatly into the html. Also the development of mvc frameworks did a good job separating out logic and view so less skills developers can work on certain parts.

    • @VitalijMik
      @VitalijMik 2 года назад

      @@lionelthetechlead8839 AS i told. You can skip the template engine if you know what you do. But i would never recommend this to a junior Developer, he will forget to call the escape method or he will call Controller within Template because he can

  • @rasimyilmaz_1985
    @rasimyilmaz_1985 3 года назад

    I cloud not find render function can you give example

  • @eybietie
    @eybietie 3 года назад

    yeah well thing is there is lots of projects oyu eventually have to work on using twig. should I refer to your video every time? XD

    • @lionelthetechlead8839
      @lionelthetechlead8839  3 года назад +2

      Of course. Just because something is widespread doesn't make it correct.

    • @eybietie
      @eybietie 3 года назад +1

      @@lionelthetechlead8839 it's not about something being correct. it's about who pays for what. if you as product owner have a system running with twig you get yourself people working with twig. the end. didn't say I disagree with you but in reality you often face old environments. that's just the nature of it.

  • @japetsaberon5061
    @japetsaberon5061 3 года назад +2

    What are you inputs about livewire?

    • @lionelthetechlead8839
      @lionelthetechlead8839  3 года назад

      Never heard of it. Then again, almost 10 frameworks a month appear all the time.

    • @japetsaberon5061
      @japetsaberon5061 3 года назад

      @@lionelthetechlead8839 livewire is like vue but in php I don't know if it is only works with laravel

    • @lionelthetechlead8839
      @lionelthetechlead8839  3 года назад

      @@japetsaberon5061 Ok I spent about 5 minutes looking thru. Here's a few points. It is heavily dependent on Laravel, that's a bad thing if you want to work on hybrid or just without a laravel. 2. The syntex is a little older. Vue is already using @click which is a lot cleaner. To me this looks a lot like meteor which is neither great at front or back. The last thing is the community is small and laravel vue is more mainstream.

    • @japetsaberon5061
      @japetsaberon5061 3 года назад

      @@lionelthetechlead8839 thank you sir for the info. Im looking forward to learn more in php

    • @Beauty-hj7kc
      @Beauty-hj7kc 4 месяца назад

      man, learn what u want, alpine js substitutes vuesjs easily and is more clean, which is a good combination with livewire, bc livewire works with ajax at the server side, dont let just a random opinion decide what ur going to learn@@japetsaberon5061

  • @potato7083
    @potato7083 3 года назад

    Thank u, I was actually searching for blade template tutorial but i stumbled on this first.

    • @lionelthetechlead8839
      @lionelthetechlead8839  3 года назад

      Blade is so PHP 5. Some of the comments is of using a template engine is like Using a bicycle because you are afraid of speeding in your car.

  • @user-te7bp7mf3e
    @user-te7bp7mf3e Год назад

    Thanks a lot for the explication.

  • @patricksantino4131
    @patricksantino4131 2 года назад +2

    You got a point. I worked with someone in one laravel application and blade can be damned. Most of the time we use js framework for frontends.

    • @lionelthetechlead8839
      @lionelthetechlead8839  2 года назад +1

      Exactly. You have to at least have some js so why bother learning a third sudo language called the template engine.

  • @user-ig7kw1tq1y
    @user-ig7kw1tq1y Месяц назад

    Hi , what is php e2 ?

  • @tmaddy2712
    @tmaddy2712 3 года назад +4

    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.

  • @johannesvandemerwe
    @johannesvandemerwe 10 месяцев назад +1

    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).

    • @CottidaeSEA
      @CottidaeSEA 9 месяцев назад

      I see this issue at work (ecommerce) where we have a bunch of values being evaluated all over the place in the template just to see if the product can be purchased. The information the template should have regarding that is a single value, isBuyable, or is_buyable if you're a heretic. This will greatly simplify the template, because logic is now extremely minimal in the template. You could even take it a step further and send the templates regarding whether you can purchase the product (or render a different template) to reflect the parts of the product page which will be affected.
      Logic in templates is a design flaw and a massive skill issue, not a templating issue.

  • @timucinbahsi445
    @timucinbahsi445 3 года назад +2

    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.

    • @lionelthetechlead8839
      @lionelthetechlead8839  3 года назад

      I use the yii2 email template and all it has is if you keep it just to var replacements.

    • @neekfenwick
      @neekfenwick Год назад

      ​@@lionelthetechlead8839 So Yii2 employs a template engine approach to generating its output, which is exactly what your video title says not to do? You've just pushed the thing you discourage further down the tech stack, you're still using a templating engine, but one wrapped in a more capable framework. I think you've caught yourself coming and going in your own argument, if stated more clearly I could appreciate your point. I think you're trying to say that we shouldn't write our own PHP code that directly employs a basic templating engine like Twig etc when generating HTML for serving to the browser. That's a good point. It avoids cases where one has a good reason to use these templating systems to generate content in other situations, which can be quite diverse especially in a system that happens not to be running in your preferred Yii2 framework, there are lots of legacy PHP applications out there in that scenario. Two simple examples that jump to mind are email content generation (as said by others here) and 3rd party sales platform content generation such as eBay, Amazon etc, that your PHP code base may be generating. There are some absolutely weird statements you make in this video also, such as "no longer needed to separate PHP and code". Maybe script your videos next time, your points will hopefully come over better. And please, the clickbait titles, they burn.

  • @NoahNobody
    @NoahNobody 5 месяцев назад

    Have you heard about the miracle of htmx?

    • @lionelthetechlead8839
      @lionelthetechlead8839  5 месяцев назад

      Yes. It looks somewhat like vue js adding more power into the html tags itself. I like vue.js as a front-end engine to do more of the work as you get the full power of js.

  • @hbgl8889
    @hbgl8889 2 года назад +9

    "Just use

    • @TheInimicus
      @TheInimicus 2 года назад +1

      Twig and smarty doesn't escape anything by default. Only blade do it.

    • @hbgl8889
      @hbgl8889 2 года назад +3

      ​@@TheInimicus Twig in combination with symfony automatically escapes variables. But yeah, if a templating engine requires you to manually escape stuff, then don't use it.

  • @lserranoit
    @lserranoit Год назад

    When I Find a way to do @yield / @section with pure PHP I won't use blade anymore

    • @lionelthetechlead8839
      @lionelthetechlead8839  Год назад

      hum... very interesting challenge. Send me an example and I'll think of a video to replace them.

  • @rihulfaakbar2261
    @rihulfaakbar2261 Год назад

    No offense but the title kinda likes an order not suggestion. It would be great if its like a suggestion so people have their own point of view. IMO, you can't expect people will do anything you told them to, BUT if its a suggestion, they will save it for later preferences.

  • @yunusarif6963
    @yunusarif6963 3 года назад

    Bottomline, its what it is: because the tech lead said so!

  • @billyz9448
    @billyz9448 3 года назад +2

    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.

    • @lionelthetechlead8839
      @lionelthetechlead8839  3 года назад +2

      Actually they still have to {% %} symbols which just doesn't make sense for the designers to do the markups. I actually give them a 20 min video on how to make out tags because sooner or later they will have to do some logic on the frontend.

  • @god_bika
    @god_bika Год назад

    what with Laravel @section @endofsection directives?Doesnt it simplify my html?Doesn't it make my html page less or make my section peace t9 be used everywhere trough all htmls and multiple times. I thing this side of Blade is most powefull. You dont have a need to scroll those endless htmls. But yes would it be php embedding or blade's it looks dirty on page. You can commit all logic in function and then pass variables to the page. It does the same as blade.

    • @lionelthetechlead8839
      @lionelthetechlead8839  Год назад

      You can do that with render partials in a framework

    • @god_bika
      @god_bika Год назад

      @@lionelthetechlead8839 i ve made little google exploring. Say in Laravel you cannot do that w/o ajax.. And i found it expensive for the server

  • @fabianotaka
    @fabianotaka 3 года назад +9

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

    • @lionelthetechlead8839
      @lionelthetechlead8839  3 года назад +3

      That's correct. You get all the power of the backend language and you do not have to learn a second 'quasi' language.

    • @ojsojs6004
      @ojsojs6004 3 года назад

      @@lionelthetechlead8839 Hi. Make a PHP 8 review.

    • @lionelthetechlead8839
      @lionelthetechlead8839  3 года назад

      @@ojsojs6004 actually looking at it now!

  • @vagabund6778
    @vagabund6778 2 года назад +1

    You do not point out any actual downside to template engines, do you?

    • @teddyruxpin3811
      @teddyruxpin3811 2 года назад

      unnecessary bulk, unnecessary complications. and when template engines allow logic, it defeats the whole solution of the problem it's trying to solve in the first place.

    • @lionelthetechlead8839
      @lionelthetechlead8839  2 года назад

      couldn't have said it better myself!

  • @DanielOpitz
    @DanielOpitz 3 года назад

    I doubt that many (template) designers are aware of the potential XSS issues.
    How do you ensure that no one creates XSS vulnerabilities?

    • @lionelthetechlead8839
      @lionelthetechlead8839  3 года назад

      Just use a php framework. LIke yii2 has built int CSFR on the form posts that protect it from XSS. Also try to use post more than get.

    • @hbgl8889
      @hbgl8889 2 года назад

      ​@@lionelthetechlead8839 Anti-CSRF measures do not prevent XSS.

    • @lionelthetechlead8839
      @lionelthetechlead8839  2 года назад

      @@hbgl8889 give me an example.

    • @hbgl8889
      @hbgl8889 2 года назад +2

      @@lionelthetechlead8839 ​ Say you have a comment form that is protected with a CSRF token. The anti-CSRF mechanism prevents an attacker from submitting comments on behalf of another user who is currently logged in on your site. However, when you render the comment page in your PHP script, you still have to HTML-encode it like so . Otherwise, an attacker could submit malicious content like alert('pwned'); which would get executed in the browsers of anyone who views the comments page.
      The problem with PHP as a templating language is that it does not HTML-encode your variables by default. You have to manually call htmlentities each and every time. If you forget to do this only once, you might sell out the user's of your website and possible even the whole web application.

  • @aerahtv0000
    @aerahtv0000 3 года назад +8

    tell this to Laravel , they use everything at once

  • @hassaannoor
    @hassaannoor 2 года назад +2

    This makes hell a lot of sense. If you want to use templating engines for the sake of "Separation of Concerns", then why not just define the variables and require a php template file.

  • @jonahmarsden
    @jonahmarsden 2 года назад

    SSR is still king.

  • @shandercage
    @shandercage Год назад

    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.

    • @lionelthetechlead8839
      @lionelthetechlead8839  Год назад

      like setup a form that sends your data to a third party api? redirect the page to a porn site?

    • @shandercage
      @shandercage Год назад

      @@lionelthetechlead8839 no. Others things. Use PHP functions that can put the system at risk.

  • @MrGrimm1337
    @MrGrimm1337 3 года назад +1

    bro, you're flipped!

  • @aelonath
    @aelonath 2 года назад +1

    Too shallow view on templating engines and some plain wrong views. For very small projects: Yes you may not need a separate template engine, for everything else its a good advice. Performance with them is not a problem. And saying: You dont need a templating Engine since you can do stuff in JS ist just very weird ... Sorry, but thats not a good video at all.
    A few years ago i was questioning the use of templating engines myself, until i saw all the wonderfull benefits, especially in bigger projects and while working with teammates. Its about maintaining code, separation of elements, security and strongly not having business logic in templates. But there is much more to like on template engines.
    Yes php started as a sort of templating engine with some extra bits on it, but its now grown up into someting else - which is good! But its cool that you can still use it as a templating engine. That does not mean you allways should. If you using Laravel or some other Framework: Your Project is definitely big enough to use a real templating engine!

    • @supermagario
      @supermagario 2 года назад

      Agree. I can't imagine my huge Laravel projects without blade. This guy is a dumb fake tech lead. In case OP wants to prove himself... bring us real life examples, and show us why we don't need template engines!

  • @umahatokula9586
    @umahatokula9586 3 года назад +1

    Use anything that works for you. Periodt.

  • @nickvledder
    @nickvledder 3 года назад +1

    You couldn’t be more right! Thanks for pointing this out.

  • @wafyalharby
    @wafyalharby 3 года назад +2

    Rasmus said: 'don't use frameworks. Because it is heavy and reaches the same result when you use the programming directly'

    • @lionelthetechlead8839
      @lionelthetechlead8839  2 года назад +1

      He also doesn't believe in collar shirts. I think he just didn't want to start a civil war

  • @pvcomercial
    @pvcomercial 2 года назад

    Came here thinking: is he insane? got out: yeah makes sense for a lot of API first applications.
    But old systems, and the good old fashion client/server all in PHP, template engines are still a good option, perhaps not for the future, but it has it's uses.

    • @lionelthetechlead8839
      @lionelthetechlead8839  2 года назад

      Going by the developments, Template engines are slowly going out of style compared to just backend or the frontend with js frameworks.

  • @dhrubavideos
    @dhrubavideos 3 года назад

    its easy to say dont use them, as you are not going to develope or write my codes, , why dont you come with examples and tutorials in phps own templating engine

    • @lionelthetechlead8839
      @lionelthetechlead8839  3 года назад +2

      Check this example how I cut the code ruclips.net/video/tHcijydtSJw/видео.html

  • @vectorialpx
    @vectorialpx 2 года назад +1

    So, let's review:
    1. "PHP is a templating engine". First, no it's not! So, your solution is to have echos everywhere and I guess you will also need some loops, from time-to-time, so basically you create your own template engine - that needs to take care of sanitization, has a lot of copy-paste (no-plugins), mixed logic and you get cataract when you read it. Cool!
    2. "Templating engines are too bulky". You don't have to marry them, just use what you need. There is no speed issue, most of the template engines will convert into regular PHP code. Having business logic inside front-end is up to you, has nothing to do with tools.
    3. "Better ways to do it". If you want to create a SPA you don't need a templating engine, of course. However, you will use one inside the JavaScript framework, just changed the technology.
    How many dislikes do you have? :)

    • @lionelthetechlead8839
      @lionelthetechlead8839  2 года назад +1

      Getting better!

    • @vectorialpx
      @vectorialpx 2 года назад

      @@lionelthetechlead8839 I don’t agree with this video but I like that you keep PHP alive, best of luck!

  • @delvorin1841
    @delvorin1841 3 года назад

    My OCD is in overdrive because your shirt is inside out.....

  • @henryshum1666
    @henryshum1666 3 месяца назад

    Thumb up just by reading the video title.
    Always remember, one can never wake a person who pretends to be asleep.

  • @kukurock
    @kukurock Год назад

    True!

  • @maxlumnar160
    @maxlumnar160 Год назад +1

    i am a developer for 23 years, and i totally agreeeeee with you man, you so right

    • @johannesvandemerwe
      @johannesvandemerwe 10 месяцев назад

      I am a developer for almost 40 years and I think there always room for improvement. I can't imagine that those 23 years has put you to a standstill in adopting new things to improve
      your habits. 23 years ago internet was a "modem" event, including that cracking noise, now you are talking hi-speed internet. Tools have become so much better and development
      so much quicker. So tell me, how does 23 years relate to you agreeing on this subject, where I state that my almost 40 years are totally irrelevant to adopt new things like I started yesterday (sort of speak)?

    • @maxlumnar160
      @maxlumnar160 10 месяцев назад

      @@johannesvandemerwe oh you are absolutely right, from the day i made my first functional code and this day, many things changed. I am constantly learning better ways and to improve my skills, in fact i NEVER made a website that was similar to the previous in terms of technology, i always tried to do it better and better. My view on the subject, that templating engines are overkill and that you should use native php to do things, but do it in a clean way, STILL STANDS! In fact, i am not just talking words, my entire work is based on custom code that is far more maintainable and clean than using templates, and is orders of magnitude smaller and hundreds of times faster than horrible things such as wordpress (yeah i know this is not a talk about wordpress, but its the best example of how horrible wrong this direction can get). I have websites running from 2005, based on custom code, that are still valid and functional with minimal updates due to php version changes.
      Templating systems are only good in team work where you get the designer that has no clue about coding, but can do minimal html, then you can let him/her do the job..yes thats true and still stands, but for solitary projects doing templates just means you are incapable of writing clean and minimalist code.
      I respect your 40yrs of experience, i can not imagine where that puts you as a start, considering that when i started internet was just starting to move.. and i am sure that from your point of view you consider learning new templating engines is the needed thing to do, but look at the big picture, over time, none of the old templating systems remained standing, they are all more or less niche, and each web app eventually makes its own variation. However, native (vanilla) php will always remain strong, and if you can code cleanly and organized directly like this, you do not need anything else.
      As a benchmark, i make webs that have millions of visitors, and every 10ms speed improvement is crucial, because it gets multiplied by millions, so in the end, its only raw php that can win, speed-wise ..think of that. Of course that if you do it wrong, its not important what engine you use, ..writing fast code and keep it easy maintainable is a philosophy of life.

  • @joshdevofficial
    @joshdevofficial 3 месяца назад

    what is the use of DESIGN PATTERN lol HAHAHAHAHA

  • @maybeunknown21
    @maybeunknown21 3 года назад +1

    What do you mean with "you don't see any PHP appearing in the Frontend"? What's you definition of "Frontend"? PHP is and was never in a Frontend software.
    I guess you should move to a modern software development approach.

    • @lionelthetechlead8839
      @lionelthetechlead8839  3 года назад +1

      Frontend is used for presentation. If I echo html that's frontend php.

  • @mnchabel8402
    @mnchabel8402 3 года назад

    Nice video

  • @emblemcc
    @emblemcc Год назад +1

    nonsense. Apart the fact that the template engine has functions and logic tuned to frontend specifically which speeds up the frontend work the app logic should be decoupled from the frontend as much as possible. Using PHP as a template language naturally encourages programmer to do the app logic in the template. Look on Wordpress native template system.. it is a mess. That is what you stand for.

    • @lionelthetechlead8839
      @lionelthetechlead8839  Год назад +1

      wordpress was developed almost 20 years ago. Not many things you own are 20 years old and still going strong. So that's not a good example to use. I've got a new video where I came across a clients twig template that is as messy and complicated as I've seen and then people can look at it and make their own decision.

    • @Jan-yn4tl
      @Jan-yn4tl Год назад

      @@lionelthetechlead8839 Twig/Timber is awesome and way more sustainable and mature system/language for templating work than the bare PHP. The fact that people might screw things up even with good tools is yet another story. Symphony has Twig for a good reason, Laravel Blade for the same reason and the list goes on.
      The native messy Wordpress templating system is beginners friendly as beginners are messy by nature. That was one of the reasons (not the only one) what made Wordpress an ideal choice for so many tinkers not necessarily programmers.

  • @19870428
    @19870428 3 года назад +1

    Nonsense statements from incompetent person.
    Template engines are created for reason and specific use case. Try to not use template engine in projects with thousands of files and you will create video with "Please Use PHP Template Engines".

  • @mosesnandi
    @mosesnandi 11 месяцев назад

    I agree 100%. Still betting on Vanilla PHP.