// create a Twig environment $loader = new Twig_Loader_Filesystem('/path/to/templates'); $twig = new Twig_Environment($loader); // parse a template and generate output $template = $twig->load('index.html.twig'); echo $template->render(array('title' => 'Welcome'));
// create a Twig environment $loader = new Twig_Loader_Array(array( 'home' => 'Hello {{ name }}!' )); $twig = new Twig_Environment($loader); // parse a template and generate output $template = $twig->load('home'); echo $template->render(array('name' => 'Twig'));This example demonstrates how to create an instance of the `Twig_Environment` class using a `Twig_Loader_Array` and then parse a template to generate output. The output is generated by passing an array of variables to the `render` method. Package library: It is likely that this code is using the official Twig package library for PHP.