For more specific and deep things in the templates the best thing is to use .LPT templates instead of TDL.
Also, you are adding attribute to the entities right? Shouldn't be more easy (if you are usin v3) to write a plugin that add such attribute definition to the fields?