Skip to content

Instantly share code, notes, and snippets.

@igorw
Created April 21, 2011 00:05
Show Gist options
  • Save igorw/933384 to your computer and use it in GitHub Desktop.
Save igorw/933384 to your computer and use it in GitHub Desktop.
Silex app with global Twig layout
<?php
require __DIR__.'/silex.phar';
$app = new Silex\Application();
$app->register(new Silex\Extension\TwigExtension(), array(
'twig.path' => __DIR__.'/views',
'twig.class_path' => __DIR__.'/vendor/twig/lib',
));
$app->before(function () use ($app) {
$app['twig']->addGlobal('layout', $app['twig']->loadTemplate('layout.twig'));
});
$app->match('/', function () use ($app) {
return $app['twig']->render('index.twig');
});
$app->run();
{% extends layout %}
{% block content %}
<h1>Ponies</h1>
<p>
are awesome.
</p>
{% endblock %}
<!DOCTYPE HTML>
<html>
<head>
<title>Nice title here</title>
</head>
<body>
{% block content %}{% endblock %}
</body>
</html>
@feamsr00
Copy link

feamsr00 commented Feb 9, 2018

Hi There! Did you ever figure out what was going on here?

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