Twig extension

This PR supersedes PR #13