Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Twig dump error? #30

Open
csikoszoltan opened this issue May 18, 2022 · 4 comments
Open

Twig dump error? #30

csikoszoltan opened this issue May 18, 2022 · 4 comments

Comments

@csikoszoltan
Copy link

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
Copy link

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

@csikoszoltan
Copy link
Author

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
Copy link

Androlax2 commented May 18, 2022

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
Copy link
Author

It works now! Thanks for your help! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants