add hooks and debug for dumping templates