The only solution is to either edit it by hand or to use Framework builder and Themes rather than traditional Dreamweaver templates.
One limitation of Dreamweaver templates is that you have to decide whether you want to have server side code in the template or on the page and you can't have both... so you basically can't have it on the template because you typically need it on the pages. The webassist Framework builder resolves that issue as well as other issues with Dreamweaver templates.