What are some popular template systems for PHP that allow for generating pages stored in a variable?

When generating pages in PHP and storing them in a variable, using a template system can make the process easier and more organized. Some popular template systems for PHP that allow for generating pages stored in a variable include Twig, Smarty, and Blade.

// Example using Twig template system
require_once 'vendor/autoload.php';

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

$template = $twig->load('index.html');
$pageContent = $template->render(['title' => 'Home', 'content' => 'Welcome to our website']);

echo $pageContent;