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

Inject metadata with onPageProcessed, but issues with cache

Started by Muut Archive 10 years ago · 4 replies · 476 views
10 years ago

hi everyone

I m facing an issue with cache, i have a function in my theme onPageProcessed that insert open graph in head the vars come from my modular blueprints, all working ok with no cache

So if save a specific page, the others page "loose" their metadata
hope i'm clear maybe related to that thread https://getgrav.org/forum#!/plugin-development:header-injection

this is excerpt of my function
--- php
public function onPageProcessed(Event $e)
{
$page = $e['page'];
$header = $page->header();
$metadata = $page->metadata();
$uri = $this->grav['uri']->path();
$route = $page->route();

if (($uri == $route)) {
// Facebook Url
if (isset($header->seofacebookurl)) {
$seofacebookurl = $header->seofacebookurl;
$property = 'og:url';
$metadata[$property] = [ 'property' => $property, 'content' => $seofacebookurl ];
} else {
$seofacebookurl = $this->grav['uri']->url;
$property = 'og:url';
$metadata[$property] = [ 'property' => $property, 'content' => $seofacebookurl ];
}
}
}

9 years ago

sorry to bump old thread. I'm still having that issue with the cache, each time i save the page the metadatas are injected with onPageProcessed. Hope someone can put me on the right track

9 years ago

for info: i inject with $page->metadata($metadata); in my public function onPageProcessed(Event $e)

9 years ago

i try onPageInitialized instead of onPageProcessed and inside onPageInitialized function i call a private function with all my meta stuff, it seems to work

9 years ago

Only recently I began to understand how to work with dynamic content and have caching enabled. The reason why your previous method using onPageProcessed didn't work and using onPageInitialized does, is explained in Caching and Events.
The downside of using onPageInitialized is that the code in it is run on every page request. I'm curious why other pages loose their metadata when one page is saved? Do you clear the full cache somewhere?

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1330 9 years ago
Archive · by Muut Archive, 9 years ago
2 922 9 years ago
Archive · by Muut Archive, 9 years ago
2 4051 9 years ago
Archive · by Muut Archive, 9 years ago
1 2930 9 years ago
Archive · by Muut Archive, 9 years ago
3 1108 9 years ago