Well, this is not a solution, just trying to advance state by sharing some experiments.
(I've yet to find a way to test conditional compilation symbols.)
This as a way to consolidate switching debug on and off:
<#@ include file="debug.incl" #>`
some text1
<# if ( xdebug ) { #>
foo = bas;
<# } #>
more text
Where debug.incl contains:
<#
bool xdebug = true;
#>
The conditional (if) in the first file is able to see the value of xdebug, so output is altered based on the setting of xdebug
in debug.incl.
Sadly, however, the output files are not rebuilt on changes to debug.incl, despite the obvious include of it. And even a clean & rebuild doesn't seem to trigger generation, so some separate build construct is need for that...
(I did try debug.tt instead of debug.incl to no avail, switch to .incl so that debug.cs wasn't created by debug.tt.)
This didn't work very well as it doesn't see conditional compilation symbols, though does actually switch on the template debug attribute!
<#
#if DEBUG
bool xdebug = true;
#else
bool xdebug = false;
#endif
#>
some text1
<# if ( xdebug ) { #>
foo = bas;
<# } #>
more text
with <#@ template debug="true" #>
vs. <# template debug=false #>
you get the conditional output or not, respectively.