lumberjack icon indicating copy to clipboard operation
lumberjack copied to clipboard

Twig dump error?

Open csikoszoltan opened this issue 3 years ago • 4 comments

What are the steps to reproduce this issue?

Use dump() in any .twig file.

What happens?

The dumped data is not formatted in a colorful way like if you dump it in a php file.

What versions of software are you using?

Operating System: MacOS 12.3.1.

PHP Version: 8.0

Lumberjack Version: 5.0.0

Screenshot 2022-05-18 at 7 12 42

It should be like this:

Screenshot 2022-05-18 at 7 13 09

Thanks! :)

csikoszoltan avatar May 18 '22 05:05 csikoszoltan

Dumping is not possible natively in twig. I personally use this: https://github.com/djboris88/timber-debugger

Androlax2 avatar May 18 '22 08:05 Androlax2

Dumping is not possible natively in twig. I personally use this: https://github.com/djboris88/timber-debugger

I tried this but sadly I still have the issue. Weird because I'm using Timber (without Lumberjack) and its working there...

csikoszoltan avatar May 18 '22 10:05 csikoszoltan

It works well for me,

Try to use this ServiceProvider :

<?php

namespace App\Providers;

use Ajgl\Twig\Extension\BreakpointExtension;
use Rareloop\Lumberjack\Config;
use Djboris88\Twig\Extension\CommentedIncludeExtension;
use HelloNico\Twig\DumpExtension;

class TimberDebuggerServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap services.
     */
    public function boot(Config $config)
    {
        if (defined('WP_DEBUG') && WP_DEBUG && function_exists('add_filter')) {
            add_filter('timber/loader/twig', function ($twig) {
                $twig->addExtension(new CommentedIncludeExtension());
                $twig->addExtension(new DumpExtension());
                $twig->addExtension(new BreakpointExtension());

                return $twig;
            });

            /*
             * Adding a second filter to cover the `Timber::render()` case, when the
             * template is not loaded through the `include` tag inside a twig file
             */
            add_filter(
                'timber/output',
                function ($output, $data, $file) {
                    return "\n<!-- Begin output of '" . $file . "' -->\n" . $output . "\n<!-- / End output of '" . $file . "' -->\n";
                },
                10,
                3,
            );
        }
    }
}

Androlax2 avatar May 18 '22 10:05 Androlax2

It works now! Thanks for your help! :)

csikoszoltan avatar May 18 '22 11:05 csikoszoltan