What is the purpose of the template class in the PHP code provided?

The purpose of the template class in the PHP code provided is to create a reusable structure for generating HTML content with dynamic data. This allows for easier maintenance and organization of the code, as well as promoting separation of concerns between the presentation and logic layers of the application.

<?php

class Template {
    private $data = [];

    public function setData($key, $value) {
        $this->data[$key] = $value;
    }

    public function render($templateFile) {
        ob_start();
        extract($this->data);
        include $templateFile;
        return ob_get_clean();
    }
}

// Example usage:
$template = new Template();
$template->setData('title', 'Welcome to my website');
$template->setData('content', 'This is the main content of the page');
echo $template->render('template.php');

?>