Last active
August 29, 2015 13:56
-
-
Save niclasleonbock/8804739 to your computer and use it in GitHub Desktop.
Example showing how to use turbolinks (helthe/turbolinks) with silex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"require": { | |
"silex/silex": "~1.1", | |
"helthe/turbolinks": "~1.2", | |
"twig/twig": ">=1.8" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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