News for hackers. Stuff that matters.
Re:Rendering on the Web by girvo on Monday August 19, 2019 @10:47PM (#20743445)
Though no-one (for a rounded-down definition of no-one) uses PHP without front-controllers and templating systems these days, giving up that feature.
Re:Rendering on the Web by Crinus on Tuesday August 20, 2019 @06:25AM (#20745321)
> and templating systems

...but last time i checked PHP itself was a templating system. What changed?

Re:Rendering on the Web by krapp on Tuesday August 20, 2019 @06:34AM (#20745358)
PHP is not a templating system, it's a web-centric programming language. It doesn't support any of the features one would want in a modern templating system, such as auto-escaping or tainting of user supplied data, knowledge of the current rendering context, native support for HTML or XML entities, macros, template caching, etc.

All of these features and more have to be implemented as a third party framework for PHP to be effective as a templating system, which is why such systems exist.

Merely echoing HTML strings and wrapping variables in htmlspecialchars() does not a "templating system" make. If it did, then every programming language would also be a templating system as long as it could output a string of characters to the necessary port.

Re:Rendering on the Web by Crinus on Tuesday August 20, 2019 @10:07AM (#20747187)
I was thinking about being able to write regular HTML with code <?php ... ?> and variable expansions like <?=$foo?> with uses like having a for loop over stuff (like, e.g., table records) and inside the body including another PHP file that is the HTML to write with <??> tags that reference to the object looped over.

It has been a very very long time since i used PHP for anything serious (or did any web programming at all) but to me that sounds like templates. Perhaps you are referring to something else with the word "template"?

Re:Rendering on the Web by girvo on Wednesday August 21, 2019 @08:10PM (#20763336)
Modern PHP isn't written that way, is the point. For better or worse.
Re:Rendering on the Web by Crinus on Thursday August 22, 2019 @06:44AM (#20766580)
Yes, but my original question was that it can be written that way and since it can written that way, why do you need to implement a template system when the language you are implementing that template system can also function as a template system itself? Isn't it a waste of time and resources?
Re:Rendering on the Web by krapp on Thursday August 22, 2019 @09:26AM (#20767755)
>why do you need to implement a template system when the language you are implementing that template system can also function as a template system itself?

Because PHP, natively, doesn't provide the features that a modern template system needs to be safe, scalable or productive. PHP doesn't recognize HTML or XML as a type, or a "template" as a thing, automatically escape user supplied data (correctly, based on context) or correctly deduce content-type headers or route requests or any number of things one expects of a modern framework or templates. As a PHP application grows in complexity, you will, inevitably, find yourself reinventing frameworks. So might as well just use one that's already been proven in the wild and optimized.

All PHP has is string concatenation. It's "templating system" is blind string concatenation - that's it.