Skip to content

Instantly share code, notes, and snippets.

@lukeholder
Last active December 15, 2015 17:59
Show Gist options
  • Save lukeholder/5299958 to your computer and use it in GitHub Desktop.
Save lukeholder/5299958 to your computer and use it in GitHub Desktop.
twig in silex
{
"require": {
"silex/silex": "1.0.*@dev",
"twig/twig": ">=1.8,<2.0-dev",
"symfony/twig-bridge": "~2.1",
"monolog/monolog": ">=1.0.0"
}
}
<?php
// web/index.php
require_once __DIR__.'/../vendor/autoload.php';
$app = new Silex\Application();
$app['debug'] = true;
// define controllers for a blog
// $admin = $app['controllers_factory'];
$app->register(new Silex\Provider\TwigServiceProvider(), array(
'twig.path' => __DIR__.'/templates',
));
$app->get( '/', function () {
return $app['twig']->render('Hello {{ name }}!', array('name' => 'Fabien'));
});
// $app->mount( '/admin', $admin );
$app->run();
@jhonatanluiz
Copy link

$app->get( '/', function () use ($app) {
$app['twig']->render('index.twig', array('name' => 'Fabien'));
});

//index.twig

Hello {{ name }}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment