Hacker News new | ask | show | jobs
by Jaruzel 2387 days ago
I do my PHP in completely different way, which in turn was the way I did ASP back in the day, also in a weird way.

All my HTML is held in template .html files, with %%PLACEHOLDER%% text where the dynamic content should be, Then my index.php is the main 'app' loading in the templates to build the output, doing string replaces on the html, and then a single final 'echo' to send the result to the user at the end of the process.

I think this is called 'code behind' - I've just always had a problem with mixing code and layout in the same file.

Does anyone else do it like this?

2 comments

Yes, I've done it that way before. Actually just did a few weeks ago when building a frontend for a WordPress site. The frontend consumes the API and takes care of lightning-fast delivery by cutting out all the normal WordPress stuff that normally runs, when building a theme.
That's nasty. Why not just use a templating language and pump in the values you need?

https://twig.symfony.com/