Acces page.raw_route in template?

Hello
When I call a dump(page) in template, I see raw_route, but when I try to {{ page.raw_route }} or dump(page.raw_route) it shows null.
Am I making a mistake somewhere?

@fosil I don’t think you’re making a mistake… I just had a look and it’s reproducible. Same happens with other properties with underscores.

The resulting null can either mean that the value of the property is null, or the property doesn’t exist. So I tried {{ dump(page.rawRoute) }} because Grav uses camelCase for property and function names. And guess what?

It yielded ā€˜/home’

But don’t ask me why dump() shows underscores instead of camelCase…

@fosil It seems {{ dump(Page) }} is dumping the properties of Page. Page::raw_route is a protected property, while Page::rawRoute() is a public function.

I guess the debugger has access to the protected properties of Page while Twig has not.

1 Like

Yes, that’s exactly it!
Thanks for showing the way.
This is a confusing dump view, because ā€œraw_routeā€ is marked # as well as other properties that can be displayed in the template (eg route, slug, …)

@fosil Even more confusing perhaps: Page::route is also a protected property and Page::route() is a pubic function. And in Twig, functions can be called without the parenthesis… So you are calling page.route() unknowingly…

Same for protected Page::slug and public Page::slug()

Exactly!
Ideally, the dump would be able to indicate the properties and methods (in the twig syntax it doesn’t really matter) that can be reached from the twig. Similar to a PHP dump, it shows public / protected / private marked names

You might consider creating an issue or feature request at Grav’s repository at GitHub…

I created it. Thank you for your help

Ha! I was wondering if that was it when I read this, think I didn’t have to to look into it.

Yep, as I think some commenters indicated on your issue, PHPDebugbar is a third party library and unfortunately not the best tool for dumping complex objects.

It would also be interesting to consider the possibility of integrating a debug library from NetteFramework - https://tracy.nette.org/en/