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

Grav\Common\Page\Header class

Started by Muut Archive 10 years ago · 3 replies · 498 views
10 years ago

I can get the header array from the Page\Page::header() method, but it doesn't return an actual Page\Header object. I want to use the get/set methods of the Page\Header class, but can't find an example of being able to do this. I can work around it, but I'd like to avoid manually exploding the dot notation. How do I get a Page\Header object for the current page?

I apologize for low-level questions like this. I'm not a PHP native. Thanks!

10 years ago

I'm trying:

PHP
$page = $this->grav['page'];
$header = $page->header();
$result = $header->get('some.key.or.other');

But I get the following error
Call to undefined method stdClass::get()

10 years ago

I ended up with the following:

PHP
$page = $this->grav['page'];
$header = $page->header();
$header = new \Grav\Common\Page\Header((array) $header);
$header->set('metadata.some.nested', 'value');
$page->header($header->items);

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1366 9 years ago
Archive · by Muut Archive, 9 years ago
2 940 9 years ago
Archive · by Muut Archive, 9 years ago
2 4069 9 years ago
Archive · by Muut Archive, 9 years ago
1 2960 9 years ago
Archive · by Muut Archive, 9 years ago
3 1124 9 years ago