require_once __DIR__.'/../vendor/autoload.php'; $app = new Silex\Application(); $app->get('/', function () use ($app) { return 'Hello World'; }); $app->run();
require_once __DIR__.'/../vendor/autoload.php'; $app = new Silex\Application(); // Register the Twig service provider $app->register(new Silex\Provider\TwigServiceProvider(), array( 'twig.path' => __DIR__.'/views', )); // Define a route that renders a Twig template $app->get('/', function () use ($app) { return $app['twig']->render('index.html.twig', array( 'name' => 'World', )); }); $app->run();In this example, we register the Twig service provider and define a route that renders a Twig template. We also pass an array of parameters to the template, including the name "World". Package Library: Pimple, Twig.