hyoa / twig-profiler-variables-bundle
Show variables send to twig when using render method
Installs: 9
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Type:symfony-bundle
Requires
- opis/closure: ^3.1
- symfony/framework-bundle: ~3.4|~4.0
- symfony/templating: ~3.4|~4.0
- symfony/twig-bundle: ~3.4|~4.0
- symfony/var-dumper: ~3.4|~4.0
- symfony/yaml: ~3.4|~4.0
- twig/twig: ~1.0|~2.6
Requires (Dev)
- phpunit/phpunit: ~7.5
- symfony/phpunit-bridge: ^4.2
This package is auto-updated.
Last update: 2024-04-28 22:34:31 UTC
README
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'], ] ] ); } }
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