Backport Twig code so far from 2.0
Backport 2.0 customisation basics
Get rid of z_exit() - these should be exceptions - mostly are developer targetteted errors