Add template debug mode option. First apes at #3941