Templates rewriting