Pug template engine for Symfony
In the root directory of your Symfony project, open a terminal and enter:
composer require pug-php/pug-symfonyAdd in app/config/services.yml:
services:
templating.engine.pug:
class: Pug\PugSymfonyEngine
arguments: ["@kernel"]Add jade in the templating.engines setting in app/config/config.yml:
...
templating:
engines: ['pug', 'twig', 'php']Create jade views by creating files with .pug extension in app/Resources/views such as contact.html.pug with some Jade like this:
h1
| Hello
=nameThen call it in your controller:
/**
* @Route("/contact")
*/
public function contactAction()
{
return $this->render('contact/contact.html.pug', [
'name' => 'Bob',
]);
}In production, you better have to pre-render all your templates to improve performances. To do that, you have to add Pug\PugSymfonyBundle\PugSymfonyBundle in your registered bundles.
In app/AppKernel.php, in the registerBundles() method, add the Pug bundle:
public function registerBundles()
{
$bundles = [
...
new Pug\PugSymfonyBundle\PugSymfonyBundle(),
];This will make the assets:publish command available, now each time you deploy your app, enter the command below:
php bin/console assets:publish --env=prod