A few years ago there was an article on CSS Tricks introducing developers to a library called Timber.  Timber allows developers to write WordPress themes using Twig. Twig is a php templating engine that has become very popular in php communities. The popularity of Twig even led Drupal to incorporate it in version 8. Because of the popularity of Twig and the overall WordPress community size, its no surprise that a library was written to tie WordPress and Twig together.

When the CSS Tricks article came out in 2015 I will admittedly say I got super excited about the idea. Separating the php from the front-end markup sounded great, especially when trying to learn a modern php development workflow. With all the new things that come out in the development world its one of those things I never really got around to learning. Recently though I inherited a project with a theme built in Twig. I’ve got to say I’m torn.

Here is a simple example. The loop looks something like this. 

{% for post in posts %} 
{{ post.title }}
{% endfor %}

That to me for some reason is really cool. It looks a lot cleaner that a bunch of php tags and it feels like handlebars js which is something I’ve used in foundation site, and emails projects and in Jekyll projects. So a plus there.

Here is my negative, and this is from a WordPress point of view. WordPress is a large piece of software, with quite a bit of core functionality. In order to use timber you have to learn an extra layer of on top of the complexity of WordPress. Finding the Timber equivalency of a WordPress function at some points can make using Timber feel forced. That is admittedly 100% due to my newness to using Timber.

Overall I think it’s a cool way of writing a WordPress theme and I would love to write some themes with it.

Leave a Reply