diogo Posted November 7, 2015 Share Posted November 7, 2015 (edited) Guys, here's a small trick to test things out on your sites: foreach($page->children as $p) { echo "<script>console.log('" . $p->title . "')</script>"; } Now open the console and enjoy For more power make sure to check Soma's Chrome PHP Logger --- Edit: Or put this simple function or your _init.php function JSlog($str) { echo "<script>console.log('" . $str . "')</script>"; } and on your templates JSlog($page->title); Edited November 7, 2015 by diogo added the function 12 Link to comment Share on other sites More sharing options...
Ivan Gretsky Posted November 8, 2015 Share Posted November 8, 2015 Thank you, diogo! As we are in tutorial mode here, it is worth mentioning the benefits of this approach versus the common echo / print_r / var_dump. I can think of two: You can check variables on the live site, where outputting things in the document html may scare site visitors. In some cases, for example in Reno theme, html output is hard to find and read on the screen. So console log is simply clearer. I am not sure (as I have not tested it), but this technique may help debugging PW admin with its redirects. Link to comment Share on other sites More sharing options...
diogo Posted November 8, 2015 Author Share Posted November 8, 2015 I thought of this only for the frontend, really. Your first point is the main advantage for me. The second advantage is that, even if the site is not live, you don't have to decide a place on the page to output your tests, and you don't have to format the markup (for instance with <pre>) because everything will be output nicely in the console. Link to comment Share on other sites More sharing options...
tpr Posted November 8, 2015 Share Posted November 8, 2015 Sometimes I use Tracy for debugging (mainly for dumping variables). It's debugger bar sticks to the bottom right corner of the window so it's easy to spot the errors/notices. Of course when using it outside the Nette framework doesn't show queries and routing. If anyone's interested I can share how to set it up in PW (nothing special). I'll also try Soma's logger in the future. Link to comment Share on other sites More sharing options...
bernhard Posted November 11, 2015 Share Posted November 11, 2015 thanks diogo, I'm using adrian's function which can also log arrays https://processwire.com/talk/topic/4550-debugging-tips/ 2 Link to comment Share on other sites More sharing options...
diogo Posted November 11, 2015 Author Share Posted November 11, 2015 Didn't see that one from Adrian Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now