Rareloop / lumberjack

Lumberjack is a powerful MVC framework for the modern WordPress developer. Write better, more expressive and easier to maintain code.
https://lumberjack.rareloop.com
MIT License
379 stars 34 forks source link

Twig dump error? #30

Open csikoszoltan opened 2 years ago

csikoszoltan commented 2 years ago

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! :)

Androlax2 commented 2 years ago

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

csikoszoltan commented 2 years ago

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...

Androlax2 commented 2 years ago

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,
            );
        }
    }
}
csikoszoltan commented 2 years ago

It works now! Thanks for your help! :)