Pug (Jade) template engine for Symfony

Overview

Pug-Symfony

Latest Stable Version GitHub Actions StyleCI Test Coverage

Pug template engine for Symfony

This is the documentation for the ongoing version 3.0. Click here to load the documentation for 2.8

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.

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

Create Pug views by creating files with .pug extension in app/Resources/views such as contact.pug:

h1
  | Contact
  =name

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

!=form_start(form, {method: 'GET'})

Then call it in your controller:

render('contact/contact.pug', [ 'name' => 'Us', ]); } }">
namespace App\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;

class MyController extends AbstractController
{
    /**
     * @Route("/contact")
     */
    public function contactAction()
    {
        return $this->render('contact/contact.pug', [
            'name' => 'Us',
        ]);
    }
}

Configure

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

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

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

See the options in the pug-php documentation: https://phug-lang.com/#options

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 views:

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

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
Comments
  • pug-symfony and Symfony 4

    pug-symfony and Symfony 4

    Hi guys! When i run composer require pug-php/pug-symfonyin my symfony 4 project, I get error

    Using version ^2.4 for pug-php/pug-symfony
    ./composer.json has been updated
    Loading composer repositories with package information
    Updating dependencies (including require-dev)
    Your requirements could not be resolved to an installable set of packages.
    
      Problem 1
        - Installation request for __root__ dev-master -> satisfiable by __root__[dev-master].
        - pug-php/pug-symfony 2.4.0 requires symfony/symfony ^2.7 || ^3.0 || ^4.0 -> satisfiable by symfony/symfony[v2.7.0, v2.7.1, v2.7.10, v2.7.11, v2.7.12, v2.7.13, v2.7.14, v2.7.15, v2.7.16, v2.7.17, v2.7.18, v2.7.19, v2.7.2, v2.7.20, v2.7.21, v2.7.22, v2.7.23, v2.7.24, v2.7.25, v2.7.26, v2.7.27, v2.7.28, v2.7.29, v2.7.3, v2.7.30, v2.7.31, v2.7.32, v2.7.33, v2.7.34, v2.7.35, v2.7.36, v2.7.37, v2.7.38, v2.7.39, v2.7.4, v2.7.40, v2.7.5, v2.7.6, v2.7.7, v2.7.8, v2.7.9, v2.8.0, v2.8.1, v2.8.10, v2.8.11, v2.8.12, v2.8.13, v2.8.14, v2.8.15, v2.8.16, v2.8.17, v2.8.18, v2.8.19, v2.8.2, v2.8.20, v2.8.21, v2.8.22, v2.8.23, v2.8.24, v2.8.25, v2.8.26, v2.8.27, v2.8.28, v2.8.29, v2.8.3, v2.8.30, v2.8.31, v2.8.32, v2.8.33, v2.8.4, v2.8.5, v2.8.6, v2.8.7, v2.8.8, v2.8.9, v3.0.0, v3.0.1, v3.0.2, v3.0.3, v3.0.4, v3.0.5, v3.0.6, v3.0.7, v3.0.8, v3.0.9, v3.1.0, v3.1.1, v3.1.10, v3.1.2, v3.1.3, v3.1.4, v3.1.5, v3.1.6, v3.1.7, v3.1.8, v3.1.9, v3.2.0, v3.2.1, v3.2.10, v3.2.11, v3.2.12, v3.2.13, v3.2.14, v3.2.2, v3.2.3, v3.2.4, v3.2.5, v3.2.6, v3.2.7, v3.2.8, v3.2.9, v3.3.0, v3.3.1, v3.3.10, v3.3.11, v3.3.12, v3.3.13, v3.3.14, v3.3.15, v3.3.2, v3.3.3, v3.3.4, v3.3.5, v3.3.6, v3.3.7, v3.3.8, v3.3.9, v3.4.0, v3.4.1, v3.4.2, v3.4.3, v4.0.0, v4.0.1, v4.0.2, v4.0.3].
        - symfony/symfony v2.7.0 conflicts with __root__[dev-master].
        - symfony/symfony v2.7.1 conflicts with __root__[dev-master].
        - symfony/symfony v2.7.10 conflicts with __root__[dev-master].
        - symfony/symfony v2.7.11 conflicts with __root__[dev-master].
        - symfony/symfony v2.7.12 conflicts with __root__[dev-master].
        - symfony/symfony v2.7.13 conflicts with __root__[dev-master].
        - symfony/symfony v2.7.14 conflicts with __root__[dev-master].
        - symfony/symfony v2.7.15 conflicts with __root__[dev-master].
        - symfony/symfony v2.7.16 conflicts with __root__[dev-master].
        - symfony/symfony v2.7.17 conflicts with __root__[dev-master].
        - symfony/symfony v2.7.18 conflicts with __root__[dev-master].
        - symfony/symfony v2.7.19 conflicts with __root__[dev-master].
        - symfony/symfony v2.7.2 conflicts with __root__[dev-master].
        - symfony/symfony v2.7.20 conflicts with __root__[dev-master].
        - symfony/symfony v2.7.21 conflicts with __root__[dev-master].
        - symfony/symfony v2.7.22 conflicts with __root__[dev-master].
        - symfony/symfony v2.7.23 conflicts with __root__[dev-master].
        - symfony/symfony v2.7.24 conflicts with __root__[dev-master].
        - symfony/symfony v2.7.25 conflicts with __root__[dev-master].
        - symfony/symfony v2.7.26 conflicts with __root__[dev-master].
        - symfony/symfony v2.7.27 conflicts with __root__[dev-master].
        - symfony/symfony v2.7.28 conflicts with __root__[dev-master].
        - symfony/symfony v2.7.29 conflicts with __root__[dev-master].
        - symfony/symfony v2.7.3 conflicts with __root__[dev-master].
        - symfony/symfony v2.7.30 conflicts with __root__[dev-master].
        - symfony/symfony v2.7.31 conflicts with __root__[dev-master].
        - symfony/symfony v2.7.32 conflicts with __root__[dev-master].
        - symfony/symfony v2.7.33 conflicts with __root__[dev-master].
        - symfony/symfony v2.7.34 conflicts with __root__[dev-master].
        - symfony/symfony v2.7.35 conflicts with __root__[dev-master].
        - symfony/symfony v2.7.36 conflicts with __root__[dev-master].
        - symfony/symfony v2.7.37 conflicts with __root__[dev-master].
        - symfony/symfony v2.7.38 conflicts with __root__[dev-master].
        - symfony/symfony v2.7.39 conflicts with __root__[dev-master].
        - symfony/symfony v2.7.4 conflicts with __root__[dev-master].
        - symfony/symfony v2.7.40 conflicts with __root__[dev-master].
        - symfony/symfony v2.7.5 conflicts with __root__[dev-master].
        - symfony/symfony v2.7.6 conflicts with __root__[dev-master].
        - symfony/symfony v2.7.7 conflicts with __root__[dev-master].
        - symfony/symfony v2.7.8 conflicts with __root__[dev-master].
        - symfony/symfony v2.7.9 conflicts with __root__[dev-master].
        - symfony/symfony v2.8.0 conflicts with __root__[dev-master].
        - symfony/symfony v2.8.1 conflicts with __root__[dev-master].
        - symfony/symfony v2.8.10 conflicts with __root__[dev-master].
        - symfony/symfony v2.8.11 conflicts with __root__[dev-master].
        - symfony/symfony v2.8.12 conflicts with __root__[dev-master].
        - symfony/symfony v2.8.13 conflicts with __root__[dev-master].
        - symfony/symfony v2.8.14 conflicts with __root__[dev-master].
        - symfony/symfony v2.8.15 conflicts with __root__[dev-master].
        - symfony/symfony v2.8.16 conflicts with __root__[dev-master].
        - symfony/symfony v2.8.17 conflicts with __root__[dev-master].
        - symfony/symfony v2.8.18 conflicts with __root__[dev-master].
        - symfony/symfony v2.8.19 conflicts with __root__[dev-master].
        - symfony/symfony v2.8.2 conflicts with __root__[dev-master].
        - symfony/symfony v2.8.20 conflicts with __root__[dev-master].
        - symfony/symfony v2.8.21 conflicts with __root__[dev-master].
        - symfony/symfony v2.8.22 conflicts with __root__[dev-master].
        - symfony/symfony v2.8.23 conflicts with __root__[dev-master].
        - symfony/symfony v2.8.24 conflicts with __root__[dev-master].
        - symfony/symfony v2.8.25 conflicts with __root__[dev-master].
        - symfony/symfony v2.8.26 conflicts with __root__[dev-master].
        - symfony/symfony v2.8.27 conflicts with __root__[dev-master].
        - symfony/symfony v2.8.28 conflicts with __root__[dev-master].
        - symfony/symfony v2.8.29 conflicts with __root__[dev-master].
        - symfony/symfony v2.8.3 conflicts with __root__[dev-master].
        - symfony/symfony v2.8.30 conflicts with __root__[dev-master].
        - symfony/symfony v2.8.31 conflicts with __root__[dev-master].
        - symfony/symfony v2.8.32 conflicts with __root__[dev-master].
        - symfony/symfony v2.8.33 conflicts with __root__[dev-master].
        - symfony/symfony v2.8.4 conflicts with __root__[dev-master].
        - symfony/symfony v2.8.5 conflicts with __root__[dev-master].
        - symfony/symfony v2.8.6 conflicts with __root__[dev-master].
        - symfony/symfony v2.8.7 conflicts with __root__[dev-master].
        - symfony/symfony v2.8.8 conflicts with __root__[dev-master].
        - symfony/symfony v2.8.9 conflicts with __root__[dev-master].
        - symfony/symfony v3.0.0 conflicts with __root__[dev-master].
        - symfony/symfony v3.0.1 conflicts with __root__[dev-master].
        - symfony/symfony v3.0.2 conflicts with __root__[dev-master].
        - symfony/symfony v3.0.3 conflicts with __root__[dev-master].
        - symfony/symfony v3.0.4 conflicts with __root__[dev-master].
        - symfony/symfony v3.0.5 conflicts with __root__[dev-master].
        - symfony/symfony v3.0.6 conflicts with __root__[dev-master].
        - symfony/symfony v3.0.7 conflicts with __root__[dev-master].
        - symfony/symfony v3.0.8 conflicts with __root__[dev-master].
        - symfony/symfony v3.0.9 conflicts with __root__[dev-master].
        - symfony/symfony v3.1.0 conflicts with __root__[dev-master].
        - symfony/symfony v3.1.1 conflicts with __root__[dev-master].
        - symfony/symfony v3.1.10 conflicts with __root__[dev-master].
        - symfony/symfony v3.1.2 conflicts with __root__[dev-master].
        - symfony/symfony v3.1.3 conflicts with __root__[dev-master].
        - symfony/symfony v3.1.4 conflicts with __root__[dev-master].
        - symfony/symfony v3.1.5 conflicts with __root__[dev-master].
        - symfony/symfony v3.1.6 conflicts with __root__[dev-master].
        - symfony/symfony v3.1.7 conflicts with __root__[dev-master].
        - symfony/symfony v3.1.8 conflicts with __root__[dev-master].
        - symfony/symfony v3.1.9 conflicts with __root__[dev-master].
        - symfony/symfony v3.2.0 conflicts with __root__[dev-master].
        - symfony/symfony v3.2.1 conflicts with __root__[dev-master].
        - symfony/symfony v3.2.10 conflicts with __root__[dev-master].
        - symfony/symfony v3.2.11 conflicts with __root__[dev-master].
        - symfony/symfony v3.2.12 conflicts with __root__[dev-master].
        - symfony/symfony v3.2.13 conflicts with __root__[dev-master].
        - symfony/symfony v3.2.14 conflicts with __root__[dev-master].
        - symfony/symfony v3.2.2 conflicts with __root__[dev-master].
        - symfony/symfony v3.2.3 conflicts with __root__[dev-master].                                                                                                                                                                          00:04
        - symfony/symfony v3.2.4 conflicts with __root__[dev-master].
        - symfony/symfony v3.2.5 conflicts with __root__[dev-master].
        - symfony/symfony v3.2.6 conflicts with __root__[dev-master].
        - symfony/symfony v3.2.7 conflicts with __root__[dev-master].
        - symfony/symfony v3.2.8 conflicts with __root__[dev-master].
        - symfony/symfony v3.2.9 conflicts with __root__[dev-master].
        - symfony/symfony v3.3.0 conflicts with __root__[dev-master].
        - symfony/symfony v3.3.1 conflicts with __root__[dev-master].
        - symfony/symfony v3.3.10 conflicts with __root__[dev-master].
        - symfony/symfony v3.3.11 conflicts with __root__[dev-master].
        - symfony/symfony v3.3.12 conflicts with __root__[dev-master].
        - symfony/symfony v3.3.13 conflicts with __root__[dev-master].
        - symfony/symfony v3.3.14 conflicts with __root__[dev-master].
        - symfony/symfony v3.3.15 conflicts with __root__[dev-master].
        - symfony/symfony v3.3.2 conflicts with __root__[dev-master].
        - symfony/symfony v3.3.3 conflicts with __root__[dev-master].
        - symfony/symfony v3.3.4 conflicts with __root__[dev-master].
        - symfony/symfony v3.3.5 conflicts with __root__[dev-master].
        - symfony/symfony v3.3.6 conflicts with __root__[dev-master].
        - symfony/symfony v3.3.7 conflicts with __root__[dev-master].
        - symfony/symfony v3.3.8 conflicts with __root__[dev-master].
        - symfony/symfony v3.3.9 conflicts with __root__[dev-master].
        - symfony/symfony v3.4.0 conflicts with __root__[dev-master].
        - symfony/symfony v3.4.1 conflicts with __root__[dev-master].
        - symfony/symfony v3.4.2 conflicts with __root__[dev-master].
        - symfony/symfony v3.4.3 conflicts with __root__[dev-master].
        - symfony/symfony v4.0.0 conflicts with __root__[dev-master].
        - symfony/symfony v4.0.1 conflicts with __root__[dev-master].
        - symfony/symfony v4.0.2 conflicts with __root__[dev-master].
        - symfony/symfony v4.0.3 conflicts with __root__[dev-master].
        - Installation request for pug-php/pug-symfony ^2.4 -> satisfiable by pug-php/pug-symfony[2.4.0].
    
    Installation failed, reverting ./composer.json to its original content.
    

    I create my application use composer create-project symfony/skeleton my-project from symfony docs

    My composer.json

    {
        "type": "project",
        "require": {
            "php": "^7.1.3",
            "ext-iconv": "*",
            "sensio/framework-extra-bundle": "^5.1",
            "symfony/console": "^4.0",
            "symfony/dependency-injection": "^4.0",
            "symfony/flex": "^1.0",
            "symfony/form": "^4.0",
            "symfony/framework-bundle": "^4.0",
            "symfony/lts": "^4@dev",
            "symfony/orm-pack": "^1.0",
            "symfony/translation": "^4.0",
            "symfony/twig-bundle": "^4.0",
            "symfony/validator": "^4.0",
            "symfony/yaml": "^4.0"
        },
        "require-dev": {
            "symfony/debug": "^4.0",
            "symfony/dotenv": "^4.0",
            "symfony/profiler-pack": "^1.0",
            "symfony/maker-bundle": "^1.0",
            "symfony/web-profiler-bundle": "^4.0"
        },
        "config": {
            "preferred-install": {
                "*": "dist"
            },
            "sort-packages": true
        },
        "autoload": {
            "psr-4": {
                "App\\": "src/"
            }
        },
        "autoload-dev": {
            "psr-4": {
                "App\\Tests\\": "tests/"
            }
        },
        "replace": {
            "symfony/polyfill-iconv": "*",
            "symfony/polyfill-php71": "*",
            "symfony/polyfill-php70": "*",
            "symfony/polyfill-php56": "*"
        },
        "scripts": {
            "auto-scripts": {
                "cache:clear": "symfony-cmd",
                "assets:install --symlink --relative %PUBLIC_DIR%": "symfony-cmd"
            },
            "post-install-cmd": [
                "@auto-scripts"
            ],
            "post-update-cmd": [
                "@auto-scripts"
            ]
        },
        "conflict": {
            "symfony/symfony": "*"
        },
        "extra": {
            "symfony": {
                "id": "01C330YXSR663BC31PR409BGSM",
                "allow-contrib": false
            }
        }
    }
    
    bug 
    opened by GreenSuslik 11
  • Global template variables not defined

    Global template variables not defined

    First, thank you for this very handy bundle.

    Testing pug template with symfony we've found that the app variable is not defined when rendering (http://symfony.com/doc/current/book/templating.html#global-template-variables).

    The error appends there: each flash_message in app.session.flashbag.get('error')

    And here is the complied version: <?php foreach (\Jade\Compiler::getPropertyFromAnything(\Jade\Compiler::getPropertyFromAnything(\Jade\Compiler::getPropertyFromAnything($app, 'session'), 'flashbag'), 'get')('error') as $flash_message) { ?>

    Do you know how we could globally define it? And if it's possible to have something like this also http://symfony.com/doc/current/cookbook/templating/global_variables.html ?

    Thank you for your help

    enhancement 
    opened by qsollet 10
  • Incomplete installation on Symfony 4

    Incomplete installation on Symfony 4

    Hello,

    When installed on a Symfony 4 project, the installation script (v 2.4) will end with the following warnings:

    Would you like us to add automatically needed settings in your config.yml? [Y/N] y
    Would you like us to add automatically the pug bundle in your AppKernel.php? [Y/N] y
    framework entry not found in config.yml.
    Sorry, AppKernel.php has a format we can't handle automatically.
    

    What should I do to to make the changes that could not be done automatically ? I tried to add the following line to /config/bundles.php:

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

    but this won't work: the bundle does not seem to be registered, since the "assets:publish" doesn't show in the list of available CLI commands.

    opened by gwenl 9
  • "extends" keyword throws Extends should be very first statement in file

    I don't really know what causes it but here's my files

    layout.pug

    html
      head
        title My Site
      body
        block content
        footer
          p 
          | Some footer text
    

    welcome.pug

    extends layout
    
    block content
        h1 Welcome #{name}
    

    When I comment out if statement which throws the exception it works fine but I don't think it will catch unexpected "extends" keyword...

    vendor\phug\parser\src\Phug\Parser\TokenHandler\ImportTokenHandler.php line 35

    bug 
    opened by coneforapine 8
  • Facing autoload.php issue when installing on Symfony 2.8.26

    Facing autoload.php issue when installing on Symfony 2.8.26

    Hi, I started with a fresh symfony 2.8 setup and tried installing pug-symfony. I executed composer require pug-php/pug-symfony, and all the dependencies got installed. However, in the last section of installation, am getting this error, when autoload.php files are being generated,

    [ErrorException] include_once(C:\xampp\htdocs\demoSymfony\autoload.php): failed to open stream: No such file or directory

    Also, i tried composer dump-autoload -o and it provided me with the same error.

    I also tried creating a blank autoload.php in the project root, and then tried composer update, and got this output,

    Loading composer repositories with package information Updating dependencies (including require-dev) Nothing to install or update Generating autoload files Package found added to be installed with npm: coffee-script@"" Package found added to be installed with npm: less@"" Package found added to be installed with npm: clean-css@"" Package found added to be installed with npm: babel-cli@"^6.10.1" Package found added to be installed with npm: babel-plugin-transform-r eact-jsx@"^6.8.0" Package found added to be installed with npm: babel-preset-es2015@"^6. 8.0" Package found added to be installed with npm: babel-preset-react@"^6.1 1.1" Package found added to be installed with npm: stylus@"" Package found added to be installed with npm: uglify-js@"" Package found added to be installed with npm: clean-css@"" Package found added to be installed with npm: pug-cli@"^1.0.0-alpha6" Packages installed.

    [ErrorException] call_user_func() expects parameter 1 to be a valid callback, clas s 'Pug\PugSymfonyEngine' not found

    update [--prefer-source] [--prefer-dist] [--dry-run] [--dev] [--no-dev ] [--lock] [--no-custom-installers] [--no-autoloader] [--no-scripts] [ --no-progress] [--no-suggest] [--with-dependencies] [-v|vv|vvv|--verbo se] [-o|--optimize-autoloader] [-a|--classmap-authoritative] [--apcu-a utoloader] [--ignore-platform-reqs] [--prefer-stable] [--prefer-lowest ] [-i|--interactive] [--root-reqs] [--] []...

    Can you please look into this and provide me a solution ?

    Reference, https://stackoverflow.com/questions/45582104/facing-issue-installing-pug-php-pug-symfony-on-symfony-2-8-26?sgp=2

    opened by ramit-mitra 8
  • Unable to load the

    Unable to load the "Symfony\Component\Form\FormRenderer" runtime issue

    Hello,

    I encountered an issue when:

    Tried to use csrf validation in symfony with pug-php

    Pug-Symfony version: 3.1

    PHP version: 7.2.14

    I expected to get:

    Normal and working login validation

    But I actually get:

    Unable to load the "Symfony\Component\Form\FormRenderer" runtime.
    

    Steps to reproduce:

    • install newest symfony
    • install newest pug-php
    • some addons like Route
    • make user entity with php bin/console make:user
    • make auth controller with php bin/console make:auth, with Login form authenticator style choosed
    • convert manually login.html.twig to login.pug

    This is code from login.pug:

    
    extends ../base.pug
    
    block 
    	title Login in!
    
    block body
    	form(method="post")
    		if error
    			if error.messageKey !== undefined
    				div.alert.alert-danger #{error.messageKey}
    			else
    				div.alert.alert-danger #{trans(error.messageData, 'security')}
    
    		if app.user
    			div.mb-3 You are logged in as #{ app.user.username },
    				a(href=path('app_logout')) Log Out
    
    		h1.h3.mb-3.font-weight-normal Please sign in
    		label(for="inputUsername") Username
    		input#inputUsername.form-control(type="text", value=last_username, name="username", required, autofocus)
    		label(for="inputPassword") Password
    		input#inputPassword.form-control(type="password", name="password", required)
    
    		div.alert.alert-danger 
    
    		.checkbox.mb-3
    		    label
    		        input(type="checkbox", name="_remember_me")
    		        |  Remember me
    
    
    		button.btn.btn-lg.btn-primary(type="submit", value=csrf_token('authenticate')) Sign in
    
    		//- See https://symfony.com/doc/current/security/remember_me.html
    
    

    The line, that is causing trouble is

    button.btn.btn-lg.btn-primary(type="submit", value=csrf_token('authenticate')) Sign in
    

    When I try to use (normally working with twig) function csrf_token('authenticate') there comes given error.

    Thanks!

    bug 
    opened by dudematthew 7
  • Pug with Symfony is not working at all

    Pug with Symfony is not working at all

    After following instructions with following steps:

    1. Installing Symfony
    2. Installing pug-symfony
    3. Installing annotations
    4. Copying template and controller content to my project

    Still, even with .pug extension, Symfony is translating template using Twig, not Pug.

    image

    I seem to have tried every possible way, but with no effect.

    What am I doing wrong? isn't it a bug?

    bug 
    opened by dudematthew 7
  • Using conditionals triggers undefined offset

    Using conditionals triggers undefined offset

    extends /admin/components/AdminBase.pug
    
    block content
        .d-flex.align-items-start
            a(href="/link").card.dashboard-card
                span(data-feather="phone").card-image-top.card-icon
                .card-body
                    h4.card-title Lorem ipsum
                    if pc === '0'
                    p.card-text lorem ipsum
                    else
                    p.card-text #{pActive} ...
    

    I don't think I screw up something in this point...

    opened by coneforapine 7
  • Using form functions

    Using form functions

    Hello & sorry, if an issue is the wrong format, but I just can't get this working.

    Switched to pug-symfony in a dev project. So far so good. Using the following in my Controller, coming from plain old Twig.

    /**
     * @Route("/", name="homepage", methods={"GET", "POST"})
     */
    public function index(Request $request)
    {
        $example = new Example();
        $form = $this->createForm(ExampleType::class, $example);
    
        $form->handleRequest($request);
        if ($form->isSubmitted() && $form->isValid()) {
            // ...
            return $this->redirectToRoute('example_goal', [
            ]);
        }
    
        return $this->render('foo/index.pug', [
            'form' => $form->createView(),
        ]);
    }
    

    How can I display the form in Pug? Tried all of the following

    h1 hi
    .content
    =form_start(form)
    
    h1 hi
    .content
    = form_start(form)
    
    h1 hi
    .content
        =form_start(form)
    
    h1 hi
    .content
        = form_start(form)
    
    h1 hi
    .content
        =form_start(=form)
    

    How do I get form_start(), form_widget() and form_end() to work in pug-symfony?

    enhancement 
    opened by kingkero 7
  •  In CheckExceptionOnInvalidReferenceBehaviorPass.php line 86 Symfony 4.2.8

    In CheckExceptionOnInvalidReferenceBehaviorPass.php line 86 Symfony 4.2.8

    After a clean installation of Symfony, I've installed the pug-symfony extension by running the command

    $ composer require pug-php/pug-symfony
    

    at the end of the installation I'm getting the following error

    Executing script cache:clear [KO]
     [KO]
    Script cache:clear returned with error code 1
    !!  
    !!  In CheckExceptionOnInvalidReferenceBehaviorPass.php line 86:
    !!                                                                                 
    !!    The service "templating" has a dependency on a non-existent service "templa  
    !!    ting.engine.twig".                                                           
    !!                                                                                 
    !!  
    !!  
    
    
    opened by pedroresende 6
  • inherit twig globals

    inherit twig globals

    This pull request will allow to pass globals from twig and also to pass app variable as it passed to twig (in case if it was somehow changed). It will simplify migration from twig to pug.

    enhancement 
    opened by Onefivefournine 6
  • Error Pug\Symfony\CssExtension

    Error Pug\Symfony\CssExtension

    Hello,

    I encountered an issue when:

    php bin/console c:c

    Result : In ExtensionSet.php line 120: Unable to register extension "Pug\Symfony\CssExtension" as extensions have already been initialized.

    Thanks!

    opened by helveden 4
Releases(3.1.1)
Owner
Pug PHP
Pug PHP
PHP Template Attribute Language — template engine for XSS-proof well-formed XHTML and HTML5 pages

PHPTAL - Template Attribute Language for PHP Requirements If you want to use the builtin internationalisation system (I18N), the php-gettext extension

PHPTAL 175 Dec 13, 2022
Smarty is a template engine for PHP, facilitating the separation of presentation (HTML/CSS) from application logic.

Smarty 3 template engine smarty.net Documentation For documentation see www.smarty.net/docs/en/ Requirements Smarty can be run with PHP 5.2 to PHP 7.4

Smarty PHP Template Engine 2.1k Jan 1, 2023
☕ Latte: the intuitive and fast template engine for those who want the most secure PHP sites.

Latte: amazing template engine for PHP Introduction Latte is a template engine for PHP which eases your work and ensures the output is protected again

Nette Foundation 898 Dec 25, 2022
View template engine of PHP extracted from Laravel

Blade 【简体中文】 This is a view templating engine which is extracted from Laravel. It's independent without relying on Laravel's Container or any others.

刘小乐 143 Dec 13, 2022
PHP template engine for native PHP templates

FOIL PHP template engine, for PHP templates. Foil brings all the flexibility and power of modern template engines to native PHP templates. Write simpl

Foil PHP 167 Dec 3, 2022
⚡️ Simple and fastly template engine for PHP

EasyTpl ⚡️ Simple and fastly template engine for PHP Features It's simple, lightweight and fastly. No learning costs, syntax like PHP template It is s

PHPPkg 19 Dec 9, 2022
Twig Template Engine to Phalcon PHP

Twig Template Engine to Phalcon PHP

Vinicius 4 Oct 7, 2022
Liquid template engine for PHP

Liquid is a PHP port of the Liquid template engine for Ruby, which was written by Tobias Lutke. Although there are many other templating engines for PHP, including Smarty (from which Liquid was partially inspired)

Harald Hanek 230 Aug 18, 2022
PHPlater, a simple template engine.

PHPlater A simple PHP template engine that lets PHP do all the logic and then append it to the HTML in the template file. It is set to solve the probl

John Larsen 2 Jun 3, 2022
A template abstraction prototype for PHP template engines

Schranz Templating A template abstraction prototype for PHP template engines. This project should help to find a way for a general Template Render Int

Schranz Templating 16 Dec 7, 2022
Standalone Skeltch templating engine for PHP

SkeltchGo is a standalone version of Glowie Skeltch templating engine for PHP, intented to use from outside the framework.

glowie 1 Nov 5, 2021
SwitchBlade: Custom Directives for the Laravel Blade templating engine

SwitchBlade: Custom Directives for the Laravel Blade templating engine

Awkward Ideas 10 Nov 29, 2022
Experimental ActiveRecord layer on top of Doctrine2 using the Twig templating engine

This is an experiment for building ActiveRecord functionality on top of Doctrine2 using the Twig templating engine. Whether it is called Propel2 or not is irrelevant.

Francois Zaninotto 85 Dec 5, 2022
Twig, the flexible, fast, and secure template language for PHP

Twig, the flexible, fast, and secure template language for PHP Twig is a template language for PHP, released under the new BSD license (code and docum

Twig 7.7k Jan 1, 2023
Native PHP template system

Plates Plates is a native PHP template system that's fast, easy to use and easy to extend. It's inspired by the excellent Twig template engine and str

The League of Extraordinary Packages 1.3k Jan 7, 2023
A lightweight template parser used by PyroCMS.

Lex Lex is a lightweight template parser. Lex is released under the MIT License and is Copyrighted 2011 - 2014 PyroCMS Team. Change Log 2.3.2 Convert

PyroCMS 102 Dec 21, 2022
Laravel package template

REPLACE Simple and flexible package template. Usage Replace all occurances of REPLACE (case sensitive) with the name of the package namespace. E.g. th

ARCHTECH 56 Aug 15, 2022
A ready-to-use Model View Controller template in PHP

PHP-MVC-Template A ready-to-use Model View Controller template in PHP Use this repo as a template! (Or clone it) Start to configure your MVC file Afte

Loule | Louis 20 Dec 26, 2022
The Templating component provides all the tools needed to build any kind of template system.

Templating Component The Templating component provides all the tools needed to build any kind of template system. It provides an infrastructure to loa

Symfony 999 Dec 25, 2022