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.
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/