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

How to access frontmatter value in a onPageProcessed event?

Started by Muut Archive 10 years ago · 6 replies · 396 views
10 years ago

in my theme i have onPageProcessed event, i can access my theme config options, but i want to access my page frontmatter values, i add $header = $page->header(); when i dump, i can see the values, but how to access them in a condition for instance ?

10 years ago

ok i can access them with a foreach, but what i don't understand is that $header have all the pages frontmatter ? how can i access only values belong to the page ?

10 years ago

$page->header() only the current page's frontmatter.

10 years ago

thanks, but why when i dump $header i see all page's frontmatter. If i echo $value from a specific key in my foreach it prints all value from different pages

10 years ago

onPageProcessed is called on all pages. You can check it's the current page by checking its route and comparing to the current route stored in $grav['uri']

10 years ago

oh! thanks, i will try that, thanks again

10 years ago

i try that code

PHP
$route = $page->route();

if ($uri == $route) {
 // do stuff
}

it works but not with home page because $route is /home and $uri is /

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1369 9 years ago
Archive · by Muut Archive, 9 years ago
2 943 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 1126 9 years ago