Add template debug mode option. First pass at #3941