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

Acces page.raw_route in template?

Solved by pamtbaau View solution

Started by fosil 7 years ago · 10 replies · 872 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...

1 reply
last edited 11/13/19 by pamtbaau
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

Suggested topics

Topic Participants Replies Views Activity
General · by jean-louis67, 3 days ago
2 81 2 days ago
General · by Andy Miller, 7 days ago
0 146 7 days ago
General · by Veehem, 1 week ago
0 145 1 week ago
General · by milkboy, 1 week ago
0 138 1 week ago
General · by ian russell, 2 weeks ago
2 226 2 weeks ago