// index.php require_once 'vendor/autoload.php'; $loader = new \Twig\Loader\FilesystemLoader('views'); $twig = new \Twig\Environment($loader); $template = $twig->load('index.html.twig'); $data = [ 'title' => 'Hello World!', 'content' => 'This is my first web page using Twig.' ]; echo $template->render($data);
// index.php require_once 'vendor/autoload.php'; $smarty = new Smarty(); $smarty->setTemplateDir('views'); $smarty->assign('title', 'Hello World!'); $smarty->assign('content', 'This is my first web page using Smarty.'); $smarty->display('index.tpl');
// index.php require_once 'vendor/autoload.php'; use Jenssegers\Blade\Blade; $views = __DIR__ . '/views'; $cache = __DIR__ . '/cache'; $blade = new Blade($views, $cache); echo $blade->make('index', ['title' => 'Hello World!', 'content' => 'This is my first web page using Blade.'])->render();In this example, we use the Blade template engine to render an HTML page. We first load the Blade library and set the views and cache directories. We then render the index template and pass in an array of data to be used in the template rendering. Finally, we output the rendered template using the `render()` method. Package library: Blade