In what scenarios should include() be used within a TemplateEngine class in PHP, and how can it affect the output of the template file?

The include() function in PHP should be used within a TemplateEngine class when you want to include external template files or partials within your main template file. This can help in organizing your code and reusing common template elements across multiple pages. By using include(), you can separate the logic and presentation layers of your application, making it easier to maintain and update.

class TemplateEngine {
    public function render($templateFile, $data = []) {
        ob_start();
        extract($data);
        include($templateFile);
        return ob_get_clean();
    }
}

// Example usage
$templateEngine = new TemplateEngine();
echo $templateEngine->render('header.php');
echo $templateEngine->render('content.php', ['title' => 'Hello World']);
echo $templateEngine->render('footer.php');