$view = 'home.php'; // The name of the view file include($view); // Load the view file
$user = ['name' => 'John', 'age' => 30]; // Some data to pass to the view $view = 'profile.php'; // The name of the view file include($view); // Load the view file
require_once 'vendor/autoload.php'; $loader = new \Twig\Loader\FilesystemLoader('views'); $twig = new \Twig\Environment($loader); echo $twig->render('home.twig', ['title' => 'Home Page']);In this example, we are using the Twig template engine to load the view file. The view file is written in Twig syntax, and the data is passed using an associative array. Package library: Twig Template Engine.