$loader = new Twig_Loader_Filesystem('/path/to/templates'); $twig = new Twig_Environment($loader, [ 'debug' => true, // enable debug mode ]); // render a template echo $twig->render('my-template.twig', [ 'foo' => 'bar', ]);
$twig = new Twig_Environment($loader, [ 'debug' => true, ]); // add a custom extension $twig->addExtension(new MyCustomExtension()); // add a custom function $twig->addFunction(new Twig_Function('my_function', function ($arg) { return strtoupper($arg); })); // render a template using our custom extension and function echo $twig->render('my-template.twig', [ 'foo' => 'bar', ]);In this example, we create a new Twig_Environment instance with debug mode enabled. We then add a custom extension and function to the environment. Finally, we render a template using our custom extension and function. The Twig library provides a powerful and flexible templating system for PHP, and Twig_Environment is a key component of that system. By using the isDebug property and other features of this class, you can customize and extend Twig to meet your specific needs.