How do you debug with blade and sage 9?

blade
sage9

#1

Hi all. I’m really new to templating. How do you correctly debug blade? All I get is a reference to the compiled file. What is your workflow for this? I’ve been looking through the best practice thread but still cant wrap my head around how to debug.


#2

I just ran into this issue as well. Digging into it a little more now, if I figure something out I’ll post it back, otherwise if anyone has some advice on this it would be greatly appreciated.


#3

Use whoops

There is a WordPress implementation here. Just make sure you don’t accidentally leave WP_DEBUG enabled on a live site, it dumps your environmental variables on the debug screen thus dumping your database credentials.

Otherwise, it should easily solve the headache of debugging.


#4

Are you using wps? I get a fatal error on activation.


#5

You need to composer install in its directory if you didn’t use composer create-project


#6

Gotcha. Will give it a whirl later!


#7

You can also use it as a theme dependency other than a wp-plugin


#8

Hmm…

WPS may need some quality of life updates. It appears to be breaking my AJAX in the backend.


#9

This might be helpful - https://stackoverflow.com/questions/28501077/phpstorm-unable-to-set-breakpoints-in-blade-php-files


#10

FWIW, the link above is working for me. Dropping @php(xdebug_break) into a Blade template kicks off the debugger for me.

It’s a little weird because you end up stepping through the compiled PHP file, but all the variables are accessible. Regardless it seems like most of the debug action is probably going to take place in the controller anyway.


#11

I installed Whoops directly as a require-dev in composer.json.

"require-dev": {
    ...
    "filp/whoops": "^2.1",
    ...
},

Then registered it in my setup.php file.

function registerWhoops() {
    $whoops = new \Whoops\Run;
    $whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler);
    $whoops->register();
}
if( WP_DEBUG ) registerWhoops();