Refactor template engine as library

This pull request fixes Trac ticket #17093.
The (minor) concern I raise here about existing duck-typed loaders would be addressed by turning this into a `getattr` defaulting to `False`.