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/