The SitePoint PHP blog has a new tutorial posted showing you how to create your own Twig template following a TDD (test-driven development) mentality.
Twig is a powerful, yet easy to master template engine. It is also my personal favorite as all my web development is based on either Symfony or Silex. Apart from its core syntax ({{ ... }} and {% ... %}), Twig has built-in support for various filters. A filter is like a “converter”. It receives certain original data (a string, a number, a date, etc) and by applying a conversion, outputs the data in a new form (as a string, a number, a date, etc).
He starts with a brief introduction to what filters in Twig are and some simple ways to use them. From there he gets into building a custom filter, starting with the tests first (hence the test-driven design). He walks you through the creation of a filter that turns times into relative strings, like "Just now" or "Within an hour". He shows how to make the extension classes and integrate it into a Symfony application.