Refactor templates in php