Template Engines: Laravel's Blade, Twig, Plates, Jade... more?

I’ve managed to build up some nice, reusable packages that allow using one of several PHP template engines. I plan to share these soon.

They’re installable via composer, and you can use these engines directly on files in your site/templates directory, rather than having to create a separate site/views or site/twig directory. (I went down that road, and you end up creating many files. And it just doesn’t feel right to have your template file load another template file.)

Currently, I’ve got these engines working:

Not for Core!

I am not suggesting nor requesting that we bring template engines into core. Keep Kirby clean and simple.

Extensible

I’ve built a ViewInterface and an abstract View class. With an interface and an abstract class defined, it’s fairly easy to code up an implementation for any other PHP-based template engine.

Why Template Engine?

When building large sites or applications in Kirby, it can be very helpful to have the power that template engines can bring, especially for Layout Inheritance, Macros, and Composite Partials.

Additionally, if you’re setting up lots of custom routes and handlers, it’s much easier to reuse your templates, without having to fake a \Page object.

Some other reasons could be:

  • Maybe you already have views in another system or website, and you’d like to use those instead of porting them to Kirby
  • Maybe your HTML/CSS prototype was built in a template language, but you want to keep them in the template language; you don’t want to compile them all and rip them up into HTML/PHP snippets and HTML/PHP templates.
  • Maybe you just really love the template language
  • Maybe you have ten layouts, and breaking things into many snippet header/footers is just too confusing or cumbersome

Questions for all that are interested

  • Is anyone interested at all in this? (I’ll share it anyway, when it’s ready)
  • Any other PHP-based template engines would you like to see?
  • Any strange use cases you’ve experienced that may be worth supporting in my libraries?

FYI: https://github.com/getkirby/kirby/issues/299

1 Like