Not long ago, I posted about PHP templating in just PHP (which is basically HEREDOC syntax). I’m literally using that technique for some super basic templating I needed to do on this very WordPress site. The main pushback was that this kind of thing can be an XSS vulnerability. In my case, it’s not, because I’m not using it for anything other than an abstraction convenience for my own hand-written strings.
Since then, we’ve had a couple of good articles about templating and I’ve seen some other approaches. I thought I’d make a quick link dump of them.
- Chris Geelhoed took a different approach than I did, passing data to a function then using a
requirestatement for a template file that expects global variables you set right before the
- If you’re into the idea of using Twig as a PHP templating engine on your WordPress site, check out Timber. TJ Fogarty has written about this for us.
- If Timber is a little heavy-handed, check out Sprig from Russell Heimlich. I really like this approach!
- Jonathan Land shared how you can use Vue (inline) templates to do your templating, even in WordPress-land.
- Charlie Walter wrote about many ways to approach PHP templating in WordPress, like in Jade, Mustache, and Twig, as well as some interesting combinations.
- It was the first I’ve heard of this, but a templating language called TinyButStrong seems to fit the bill and looks like it’s actively developed.
Also check out plates: https://platesphp.com/
Twig style inheritance in native PHP without the need to compile.
or blade -> https://laravel.com/docs/blade
used in sage -> https://roots.io/sage/docs/blade-templates/
Blade needs to be compiled.
This is a bit of self-promotion, but I think it’s on point and relevant. I made a WordPress boilerplate that is component-based like the .js frameworks are, but it uses Twig to make components, you can check out the description of how it works and the link to the repo on the blog I wrote https://locastic.com/blog/modern-wordpress-boilerplate-setup/.