Home

Awesome

Description

This bundle lets you use the Kint library in your Twig templates.

This bundle adds a new Twig kint() function which is a replacement for the Twig dump() function. Extremely easy to use but very powerful. Some of its features:

Installation

Using Composer (for Symfony 2.1)

Add the Kint Bundle in your composer.json file:

{
    "require": {
        "cg/kint-bundle": "dev-master"
    }
}

Now tell composer to download the bundle by running the command:

$ php composer.phar update Cg/KintBundle

Composer will install the bundle and Kint in your project's vendor directory.

Using Deps (for Symfony 2.0)

1- Add this to your Deps file:

[Kint]
    git=http://github.com/raveren/kint.git
    target=raveren/kint

[KintBundle]
    git=http://github.com/barelon/CgKintBundle.git
    target=bundles/Cg/KintBundle

2- run ./bin/vendors install

3- Add the Cg namespace to your autoloader:

// app/autoload.php

$loader->registerNamespaces(array(
    // ...
    'Cg' => __DIR__.'/../vendor/bundles',
));

4- Add a classmap to your autoloader so that it can load the Kint class. Add this line at the beginning of the app/autoload.php file

use Symfony\Component\ClassLoader\MapClassLoader;

And add this code snippet at the end of that file:

// Create map autoloader
$mapLoader = new MapClassLoader(array(
    'Kint' => __DIR__.'/../vendor/raveren/kint/Kint.class.php',
));

$mapLoader->register();

Update your AppKernel (for both Symfony 2.1 and 2.0)

Finally, enable the bundle in the kernel:

// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new Cg\KintBundle\CgKintBundle(),
    );
}

Usage

Within any Twig template use

{{kint(var1,var2,...)}}

This will dump on screen the values of these Twig variables. They will be shown in a beautiful format, with a collapsable hierarchical view. Click on any variable name to open or collapse one level or click the + and - signs to open or collapse all levels.

If you don´t include any variable names in your kint() call, like this:

{{kint()}}

then the whole Twig Context with all its variables will be dumped.

Configuration

In your app/config/config.yml file you can include

cg_kint:
    enabled:          true
    nesting_depth:    5
    string_length:    60

All these parameters are optional. If you don´t include them they will take the default values shown above.

License

This bundle is under the MIT license. See the complete license in the bundle:

Resources/meta/LICENSE

About

KintBundle has been created by Carlos Granados.

Kint was created by Rokas Šleinius.

See also the list of contributors.

Reporting an issue or a feature request

Issues and feature requests are tracked in the Github issue tracker.