Are there any recommended template engines for handling variable substitution in PHP?

When handling variable substitution in PHP, using a template engine can help separate the presentation logic from the business logic, making the code more maintainable and easier to read. Some recommended template engines for PHP include Twig, Blade, and Smarty. These template engines provide features like template inheritance, escaping output, and easy variable substitution.

// Example using Twig template engine for variable substitution
require_once 'vendor/autoload.php';

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

$variables = [
    'name' => 'John Doe',
    'age' => 30
];

echo $twig->render('index.html', $variables);