Template preprocessing