kylekatarnls / jade-symfony
Pug template engine for Symfony
Fund package maintenance!
kylekatarnls
Open Collective
Tidelift
Installs: 1 265
Dependents: 0
Suggesters: 0
Security: 0
Stars: 4
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: >=5.4.0
- pug-php/pug: ^2.7.1 || ^3.0.0@beta
- pug-php/pug-assets: ^1.0.1
- pug/installer: ^0.1.0
- symfony/symfony: ^2.7 || ^3.0 || ^4.0
Requires (Dev)
- codeclimate/php-test-reporter: ^0.4.0
- composer/composer: >=1.0.0
- phpunit/phpunit: ^4.8 || ^5.7 || ~6.3.0
- symfony/phpunit-bridge: ^3.3.9
Replaces
- kylekatarnls/jade-symfony: 2.4.0
README
This repository now lives on https://github.com/pug-php/pug-symfony
Pug-Symfony
Pug template engine for Symfony
Install
In the root directory of your Symfony project, open a terminal and enter:
composer require pug-php/pug-symfony
When your are asked to install automatically needed settings, enter yes ; or if you prefer, follow the manual installation steps below.
Manual alternative steps
Add pug in the templating.engines setting in app/config/config.yml by merging the following to your settings:
services: templating.engine.pug: class: Pug\PugSymfonyEngine arguments: ["@kernel"] framework: templating: engines: ['pug', 'twig', 'php']
In order to use pug cli commands, you will also need to add
Pug\PugSymfonyBundle\PugSymfonyBundle()
to your AppKenel.php.
Configure
You can set pug options by accessing the container (from controller or from the kernel) in Symfony.
$services = $kernel->getContainer(); $pug = $services->get('templating.engine.pug'); $pug->setOptions(array( 'pretty' => true, 'pugjs' => true, // ... )); // You can get the Pug engine to call any method available in pug-php $pug->getEngine()->share('globalVar', 'foo'); $pug->getEngine()->addKeyword('customKeyword', $bar);
See the options in the pug-php README: https://github.com/pug-php/pug And methods directly available on the service: https://github.com/pug-php/pug-symfony/blob/master/src/Jade/JadeSymfonyEngine.php
Initial options can also be passed in parameters in your config.yml:
parameters: pug: expressionLanguage: php
Usage
Create jade views by creating files with .pug extension in app/Resources/views such as contact.pug with some Jade like this:
h1
| Hello
=name
Then call it in your controller:
/** * @Route("/contact") */ public function contactAction() { return $this->render('contact/contact.pug', [ 'name' => 'Bob', ]); }
Deployment
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 (this
has been done automatically if you installed pug-symfony 2.3 or above with automated script):
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