4 ms·
HTML templating isn't just string interpolation, Its a whole templating engine. It's not like JSX, which is fake templating. Server side frameworks have real te
by const_cast 1y ago
HTML templating isn't just string interpolation, Its a whole templating engine. It's not like JSX, which is fake templating. Server side frameworks have real templating.
Plus, you have to convert data to HTML somewhere. If you're using react you do this typically on the front end. You traverse and read JSON and convert it to HTML... Just like you would in PHP. Just, on the front end.
- chuckadams 1y ago> You traverse and read JSON and convert it to HTML It gets converted to DOM nodes, and there is zero HTML source involved when using a component toolkit. Whereas in PHP, you can do things like this and it won't make a peep: $foo = '<h1 <um & hi=="bla""foo"""arglebargle>>>>>'; ?><?= $foo ?> Other template engines like twig or blade will at least escape it by default, but of course have a syntax for interpolating it raw, otherwise they wouldn't be very useful as template engines. That's the sort of templating I'm talking about. JSX is a tree builder syntax that doesn't even produce strings at all on the client side, and when rendered in SSR, produces HTML source that's correct by construction (syntactically anyway). You can call that "fake templating", I'd say it's not templating at all. Obviously there are other server-side template engines out there that are also correct in this fashion (HAML comes to mind), but I'm not referring to those, and neither is most of the "server-side is all you ever need" crowd.
- const_cast 1y agoI haven't seen a project that uses PHP for templating in many, many years. PHP backends use a templating engine, not PHP. They also feature components. Its the same level of abstraction as JSX but you also get type checking.
- chuckadams 1y agoI would love to see more server template engines on the abstraction level of JSX/TSX or better, but I can assure you that neither Blade nor Twig are among them. And I actually like Twig (yes, I still occasionally do templating).