---
title: Twig + WordPress = Timber
author: George Mandis <george@mand.is>
date: 2014-05-08
tags: post, post, wordpress, web development, nerdy, twig, php
---

<p>One of the things that bothers me about making WordPress themes is that there isn't always a clear delineation between logic and presentation. Some of that is due to the pseudo-template nature of PHP itself and some of that is because WordPress is just a weird, fickle beast that's the result of nearly ten years of open-source development with an admirable (if sometimes frustrating) dedication to preserving compatibility between versions and with older server environments.</p>
<p>Basically though, I want the templating aspects of WordPress to be more similar to the templating experience I get with <a href="http://www.shopify.com/?ref=snaptortoise">Shopify</a>. I've written a little about this in a post about using <a title="Why I chose Swig over Jade templates for my Node+Express project" href="/2014/02/chose-swig-jade-templates-nodeexpress-project/">Swig for templates in Node</a> but for whatever reason never thought to look for a similar solution in WordPress.</p>
<p>Instead of adding it to my long-list of open-source weekend projects to start I did some searching and stumbled across <a href="http://jarednova.github.io/timber/">Timber</a>. It's a WordPress plugin that uses the <a href="http://twig.sensiolabs.org/">Twig</a> template system which is very similar to Swig, Liquid and probably a dozen other template systems out there. The learning curve isn't particularly steep and for basic themes I suspect it will rapidly speed-up production.</p>
<p>By separating the logic and presentation into separate files — logic essentially stays in the files you've come to know in the <a href="http://codex.wordpress.org/Template_Hierarchy">WordPress template hierarchy</a> while the presentation gets moved into .twig files into a folder called views, essentially fulfilling the vc portion of the mvc paradigm — it allows me to more cleanly manage themes and projects that could have custom, web-app-like functionality <span class='footnote'>(There is a school of thought that would suggest moving a lot of this stuff into a custom plugin instead of the theme. In principle I agree but in practice... I just don't. In my experience it just further fragments the pieces of the project in an unhelpful way.)</span>.</p>
<p>&nbsp;</p>