[imp][33869] Improve the "Is debug" check for the templates. Fixes #4086