generate page template refactored