PHPackages                             pug-php/pug-symfony - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Templating &amp; Views](/categories/templating)
4. /
5. pug-php/pug-symfony

ActiveLibrary[Templating &amp; Views](/categories/templating)

pug-php/pug-symfony
===================

Pug template engine for Symfony

4.0.1(3y ago)444.4k3MITPHPPHP &gt;=8.1CI failing

Since Jun 23Pushed 3y ago3 watchersCompare

[ Source](https://github.com/pug-php/pug-symfony)[ Packagist](https://packagist.org/packages/pug-php/pug-symfony)[ GitHub Sponsors](https://github.com/kylekatarnls)[ Fund](https://opencollective.com/pug-php)[ RSS](/packages/pug-php-pug-symfony/feed)WikiDiscussions master Synced 2w ago

READMEChangelog (10)Dependencies (14)Versions (46)Used By (0)

Pug-Symfony
===========

[](#pug-symfony)

[![Latest Stable Version](https://camo.githubusercontent.com/6da1862b323d16d2679e803091f7725ffee341f8ced5a657db59837c25605e42/68747470733a2f2f706f7365722e707567782e6f72672f7075672d7068702f7075672d73796d666f6e792f762f737461626c652e706e67)](https://packagist.org/packages/pug-php/pug-symfony)[![GitHub Actions](https://github.com/pug-php/pug-symfony/workflows/Tests/badge.svg)](https://github.com/pug-php/pug-symfony/actions)[![StyleCI](https://camo.githubusercontent.com/05f62209bfddab55d26cdfb64ba8282e0cf94f1087cdfae8923de376c475bc5f/68747470733a2f2f7374796c6563692e696f2f7265706f732f36313738343938382f736869656c643f7374796c653d666c6174)](https://styleci.io/repos/61784988)[![Test Coverage](https://camo.githubusercontent.com/5e2b1097f2d7dc767b8decb73f7e59c079244086bbd72f39ae30c6615ac548ba/68747470733a2f2f636f6465636f762e696f2f67682f7075672d7068702f7075672d73796d666f6e792f6272616e63682f6d61737465722f67726170682f62616467652e7376673f746f6b656e3d797a6a456e5a7a524e6d)](https://codecov.io/github/pug-php/pug-symfony?branch=master)

[Pug template](https://phug-lang.com/) engine for Symfony

This is the documentation for the ongoing version 3.0. [Click here to load the documentation for 2.8](https://github.com/pug-php/pug-symfony/tree/2.8.0#pug-symfony)

Install
-------

[](#install)

In the root directory of your Symfony project, open a terminal and enter.

```
composer require pug-php/pug-symfony
```

When you are asked to install automatically needed settings, enter yes.

It for any reason, you do not can or want to use it, you will have to add to your **config/bundles.php** file:

```
Pug\PugSymfonyBundle\PugSymfonyBundle::class => ['all' => true],
```

Usage
-----

[](#usage)

Create Pug views by creating files with .pug extension in **templates** such as contact.pug:

```
h1
  | Contact
  =name
```

Then inject `Pug\PugSymfonyEngine` to call it in your controller:

```
namespace App\Controller;

use Pug\PugSymfonyEngine;
use Symfony\Component\HttpKernel\Attribute\AsController;
use Symfony\Component\Routing\Annotation\Route;

#[AsController]
class MyController
{
    #[Route('/contact')]
    public function contactAction(PugSymfonyEngine $pug)
    {
        return $pug->renderResponse('contact/contact.pug', [
            'name' => 'Us',
        ]);
    }
}
```

Or alternatively you can use `\Pug\Symfony\Traits\PugRenderer` to call directly `->render()` from any method of a controller (or service):

```
namespace App\Controller;

use Pug\Symfony\Traits\PugRenderer;
use Symfony\Component\HttpKernel\Attribute\AsController;
use Symfony\Component\Routing\Annotation\Route;

#[AsController]
class MyController
{
    use PugRenderer;

    #[Route('/contact')]
    public function contactAction()
    {
        return $this->render('contact/contact.pug', [
            'name' => 'Us',
        ]);
    }
}
```

No matter if your controller extends `AbstractController` as it can also render twig views, so it will just work the same as before rather you `->render('view.html.twig')` or `->render('view.pug')`.

Note: standard Twig functions are also available in your pug templates, for instance:

```
!=form(form)
```

As per

Pass the FormView as usual from the controller:

```
$task = new Task();
// ...

$form = $this->createFormBuilder($task)
    // ...
    ->getForm();

return $pug->renderResponse('home.pug', [
    'form' => $form->createView(),
]);
```

Configure
---------

[](#configure)

You can inject `Pug\PugSymfonyEngine` to change options, share values, add plugins to Pug at route level:

```
// In a controller method
#[Route('/contact')]
public function contactAction(\Pug\PugSymfonyEngine $pug)
{
    $pug->setOptions(array(
      'pretty' => true,
      'pugjs' => true,
      // ...
    ));
    $pug->share('globalVar', 'foo');
    $pug->getRenderer()->addKeyword('customKeyword', $bar);

    return $pug->renderResponse('contact/contact.pug', [
        'name' => 'Us',
    ]);
}
```

If you use the `PugRenderer` trait, you don't need to inject the service again and can just use `$this->pug`.

Same can be run globally on a given event such as `onKernelView` to apply customization before any view rendering.

See the options in the pug-php documentation:

Initial options can also be passed in parameters in your **config/services.yaml**:

```
# config/services.yaml
parameters:
    # ...
    pug:
        expressionLanguage: php
```

Note: you can also create a **config/packages/pug.yaml** to store the Pug settings.

Globals of Twig are available in Pug views (such as the `app` variable to get `app.token` or `app.environment`) and any custom global value or service you will add to **twig.yaml**:

```
# config/packages/twig.yaml
twig:
    # ...
    globals:
        translator: '@translator'
```

Make the translator available in every view:

```
p=translator.trans('Hello %name%', {'%name%': 'Jack'})
```

Keys (left) passed to `globals` are the variable name to be used in the view, values (right) are the class name (can be `'@\App\MyService'`) or the alias to resolve the dependency injection. It can also be static values such as `ga_tracking: 'UA-xxxxx-x'`.

If you need more advanced customizations to be applied for every Pug rendering, you can use interceptor services.

```
# config/services.yaml
parameters:
    # ...
    pug:
        interceptors:
            - App\Service\PugInterceptor
            # You can add more interceptors

services:
    # ...

    # They all need to be public
    App\Service\PugInterceptor:
        public: true
```

Then the interceptor would look like this:

```
// src/Service/PugInterceptor.php
namespace App\Service;

use Pug\Symfony\Contracts\InterceptorInterface;
use Pug\Symfony\RenderEvent;
use Symfony\Contracts\EventDispatcher\Event;

class PugInterceptor implements InterceptorInterface
{
    public function intercept(Event $event)
    {
        if ($event instanceof RenderEvent) {
            // Here you can any method on the engine or the renderer:
            $event->getEngine()->getRenderer()->addKeyword('customKeyword', $bar);
            $event->getEngine()->getRenderer()->addExtension(MyPlugin::class);

            // Or/and manipulate the local variables passed to the view:
            $locals = $event->getLocals();
            $locals['foo']++;
            $event->setLocals($locals);

            // Or/and get set the name of the view that is about to be rendered:
            if ($event->getName() === 'profile.pug') {
                // if user variable is missing
                if (!isset($event->getLocals()['user'])) {
                    $event->setName('search-user.pug');
                    // Render the search-user.pug instead of profile.pug
                }
            }
        }
    }
}
```

As services, interceptors can inject any dependency in their constructor to use it in the `intercept` method:

```
class PugInterceptor implements InterceptorInterface
{
    private $service;

    public function __construct(MyOtherService $service)
    {
        $this->service = $service;
    }

    public function intercept(Event $event)
    {
        if ($event instanceof RenderEvent) {
            $event->getEngine()->share('anwser', $this->service->getAnwser());
        }
    }
}
```

And interceptors are lazy-loaded, it means in the example above, neither `PugInterceptor`nor `MyOtherService` will be loaded if they are not used elsewhere and if the current request does not end with a pug rendering (pure-Twig view, API response, websocket, etc.) so it's a good way to optimize things you only need to do before pug rendering.

Deployment
----------

[](#deployment)

In production, you better have to pre-render all your templates to improve performances using the command below:

```
php bin/console assets:publish --env=prod
```

Security contact information
----------------------------

[](#security-contact-information)

To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security). Tidelift will coordinate the fix and disclosure.

###  Health Score

41

—

FairBetter than 87% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity29

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity85

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 99.3% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~61 days

Recently: every ~251 days

Total

41

Last Release

1205d ago

Major Versions

1.3.3 → 2.0.02016-07-29

2.8.0 → 3.0.0-beta.12020-02-06

3.1.1 → 4.0.02023-03-05

PHP version history (5 changes)2.2.1PHP &gt;=5.5.9

2.3.1PHP &gt;=5.4.0

3.0.0-beta.1PHP ^7.2.5

3.1.0PHP ^7.2.5 || ^8.0

4.0.0PHP &gt;=8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/df90c422f521bf26355c3e185a59fe7afb35531af56244dfaec03ee1d0ca6f24?d=identicon)[kylekatarn](/maintainers/kylekatarn)

---

Top Contributors

[![kylekatarnls](https://avatars.githubusercontent.com/u/5966783?v=4)](https://github.com/kylekatarnls "kylekatarnls (280 commits)")[![carusogabriel](https://avatars.githubusercontent.com/u/16328050?v=4)](https://github.com/carusogabriel "carusogabriel (1 commits)")[![Onefivefournine](https://avatars.githubusercontent.com/u/18087962?v=4)](https://github.com/Onefivefournine "Onefivefournine (1 commits)")

---

Tags

assetsextensionjademinifyphpproductionpugpug-template-enginesymfony

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/pug-php-pug-symfony/health.svg)

```
[![Health](https://phpackages.com/badges/pug-php-pug-symfony/health.svg)](https://phpackages.com/packages/pug-php-pug-symfony)
```

###  Alternatives

[easycorp/easyadmin-bundle

Admin generator for Symfony applications

4.3k17.5M373](/packages/easycorp-easyadmin-bundle)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.4M196](/packages/sulu-sulu)[pimcore/pimcore

Content &amp; Product Management Framework (CMS/PIM/E-Commerce)

3.8k3.8M462](/packages/pimcore-pimcore)[chameleon-system/chameleon-base

The Chameleon System core.

1027.9k4](/packages/chameleon-system-chameleon-base)[open-dxp/opendxp

Content &amp; Product Management Framework (CMS/PIM)

9317.2k55](/packages/open-dxp-opendxp)[prestashop/prestashop

PrestaShop is an Open Source e-commerce platform, committed to providing the best shopping cart experience for both merchants and customers.

9.1k16.8k](/packages/prestashop-prestashop)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
