Skip to content

Instantly share code, notes, and snippets.

Created December 12, 2017 15:38
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Use Pug in a Silex app
// Install Pug with: composer require pug-php/pug
$app['view'] = function () {
return new Pug(array(
'cache' => './storage/cache',
'paths' => array(
// Here you can record differents root directories
// containing pug templates.
$app->get('/hello/{name}', function ($name) use ($app) {
// Supposing you have a template stored in ./views/hello.pug
return $app['view']->renderFile('hello', array(
'name' => $name,
// You can call the service more explicitly $app['pug'] and call explicitly
// templates files with extensions ->renderFile('hello.pug')
// but the benefit of the "view" naming and extension omit is it allow you
// to easily switch to an other template engine.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment