How can structured programming principles be applied to improve the design of a PHP template system?

Issue: The design of a PHP template system can become messy and hard to maintain without proper structure. By applying structured programming principles such as modularity, encapsulation, and separation of concerns, we can improve the organization and readability of the template system. Code snippet:

<?php

// Example of a structured PHP template system using modularity and separation of concerns

// Template class for handling the rendering of templates
class Template {
    private $data = [];

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

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

// Example usage
$template = new Template();
$template->setData('title', 'Welcome');
$template->setData('content', 'Hello, world!');

$template->render('template.php');

?>

// template.php
<!DOCTYPE html>
<html>
<head>
    <title><?php echo $title; ?></title>
</head>
<body>
    <div><?php echo $content; ?></div>
</body>
</html>