Skip to content
Grav 2.0 is officially stable. Read the announcement →

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

General

Acces page.raw_route in template?

Solved by pamtbaau View solution

Started by fosil 7 years ago · 10 replies · 759 views
7 years ago

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?

7 years ago

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

last edited 11/13/19 by pamtbaau
7 years ago Solution

@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
7 years ago

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, ...)

7 years ago

@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()

7 years ago

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

7 years ago

I created it. Thank you for your help

7 years ago

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

7 years ago

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.

Suggested topics

Topic Participants Replies Views Activity
General · by Jerry Hunt, 4 days ago
2 80 10 hours ago
General · by pamtbaau, 15 hours ago
1 51 15 hours ago
General · by Andy Miller, 1 day ago
0 45 1 day ago
General · by Marcel, 12 months ago
6 346 5 days ago
General · by Duc , 5 days ago
3 40 5 days ago