What are the advantages of using a template engine in PHP for separating HTML content from PHP functions?

Using a template engine in PHP helps to separate the presentation layer (HTML content) from the business logic (PHP functions), making the code more organized and maintainable. This separation allows front-end developers to work on the HTML templates without needing to understand or modify the PHP code, and vice versa. Additionally, template engines often provide features like template inheritance, reusable components, and caching for improved performance.

<?php
// Using the Twig template engine as an example
require_once 'vendor/autoload.php';

$loader = new \Twig\Loader\FilesystemLoader('templates');
$twig = new \Twig\Environment($loader);

// Render a template with variables
echo $twig->render('index.html', ['title' => 'Welcome to my website']);
?>