Skip to content

Instantly share code, notes, and snippets.

@niclasleonbock
Last active August 29, 2015 13:56
Show Gist options
  • Save niclasleonbock/8804739 to your computer and use it in GitHub Desktop.
Save niclasleonbock/8804739 to your computer and use it in GitHub Desktop.
Example showing how to use turbolinks (helthe/turbolinks) with silex
<?php
require_once __DIR__.'/../vendor/autoload.php';
$app = new Silex\Application();
$app['debug'] = true;
// the magic part
new Helthe\Component\Turbolinks\StackTurbolinks($app, new Helthe\Component\Turbolinks\Turbolinks());
// ...
// register twig
$app->register(new Silex\Provider\TwigServiceProvider(), array(
'twig.path' => __DIR__.'/../app/view',
));
// some sample code, requiring twig (see above)
$app->get('/', function () use ($app) {
return $app['twig']->render('index.html.twig');
});
$app->get('/about', function () use ($app) {
return $app['twig']->render('about.html.twig');
});
// ...
$app->run();
{
"require": {
"silex/silex": "~1.1",
"helthe/turbolinks": "~1.2",
"twig/twig": ">=1.8"
}
}
<!DOCTYPE html>
<html>
<head>
<!-- ... -->
<!-- example for twig, may need to be edited for other templating engines -->
<!-- only needed when using jQuery
<script src="//code.jquery.com/jquery.js"></script>
<script src="{{ app.request.basePath }}/assets/jquery.turbolinks.js"></script> -->
<!-- must be in head-tag, not body! -->
<script src="{{ app.request.basePath }}/assets/turbolinks.js"></script> <!-- can be found in /vendor/helthe/turbolinks/Helthe/Component/Turbolinks/Resources/public/js -->
<!-- ... -->
</head>
<body>
<!-- your content, just as always -->
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment