Skip to content

Latest commit

 

History

History
98 lines (79 loc) · 2.04 KB

README.md

File metadata and controls

98 lines (79 loc) · 2.04 KB

TwigProfilerVariablesBundle

Description

Allow to see variables send by a controller to the twig template. Variables that cannot be serialized are ignored (it's variable that contain closure)

Installation

The bundle is designed to work with Symfony 3.4 or 4.x. Older version are not supported.

Install the bundle via Composer:
composer require --dev hyoa/twig-profiler-variables-bundle dev-master

Enable the bundle in your kernel:

####Symfony 4.x

# config/packages/framework.yaml
framework:
    ...
    templating:
        engines: ['profiler_variables']
// config/bundles.php
<?php

return [
    ...
    Hyoa\TwigProfilerVariablesBundle\TwigProfilerVariablesBundle::class => ['dev' => true]
];

####Symfony 3.4.x

# app/config/config_dev.yml
framework:
    ...
    templating:
        engines: ['profiler_variables']
// app/AppKernel.php
<?php

    public function registerBundles()
    {
        ...
        if (in_array($this->getEnvironment(), ['dev', 'test'], true)) {
            ...
            if ('dev' === $this->getEnvironment()) {
                ...
                $bundles[] = new \Hyoa\TwigProfilerVariablesBundle\TwigProfilerVariablesBundle();
            }
        }

        return $bundles;
    }

Example

<?php


namespace App\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;

class HomeController extends AbstractController
{
    /**
     * @Route("/")
     */
    public function indexAction()
    {
        return $this->render(
            'home.html.twig',
            [
                'page' => 'home',
                'users' => [
                   ['id' => 1, 'name' => 'toto'],
                   ['id' => 2, 'name' => 'tata'],
                ]
            ]
        );
    }
}

Profiler page example

Tests

The only test is an integration that assert the profiler received correctly the variables from the controller. You can run it the following way: vendor/bin/phpunit