TemplateGenerator. Added support for custom template contexts.