3 ms·
I agree with you on PHP doing html templating well, however it just seems not big enough of a strength, if you will. I also had a decade of PHP experience befo
by godot 6y ago
I agree with you on PHP doing html templating well, however it just seems not big enough of a strength, if you will.
I also had a decade of PHP experience before transitioning to nodejs in the last few years. I first transitioned for my day job, and then also started using node for hobby projects. For hobby projects I like to keep things as simple and quick as possible (translation: so no React frontend and all that stuff), so I was trying to emulate how PHP does things and just have my node server render html from the server. I've found that almost any way I try to do it, it's a little bit more awkward in node and you end up having to choose from one of the dozen of templating libraries and learn their syntax (no-go for me).
In PHP one of my favorite things is, say you pick up a super simple routing lib like ToroPHP. In your route handlers you could skip all templating libraries altogether and simply require() a .php file that is your view html. It would simply be a file that contains HTML where you could sprinkle php statements anywhere. It's just about the the best/easiest way to template HTML output from the server for hobby projects (and I argue even for larger projects too in many cases).
What I end up doing for hobby projects in node now is usually going JAM stack. Build my frontend in Svelte (which is as close to no framework as possible), and build API server in node with Fastify. I guess where I'm going with that is that a setup like that isn't much more hassles than doing PHP and html templating for these small projects.