Mark the beginning and end of each template in debug mode (see #6841)