Closed ghost closed 4 years ago
Hi @diff-dennis
I think you need to hook into the rendering process for this case, as I'm not positive that ProcessWire can parse such deep nested objects in placeholders. You can hook after SeoMaestro::renderSeoDataValue
and modify the image url. Some more information about this hook:
Let me know if it works! :)
Cheers
Hey @diff-dennis @wanze. i already wrote the hooks for this use case:
// Add the OG:IMAGE
$wire->addHookAfter('SeoMaestro::renderSeoDataValue', function (HookEvent $event) {
$group = $event->arguments(0);
$name = $event->arguments(1);
$value = $event->arguments(2);
#bd($event);
if ($group === 'opengraph' && $name === 'image' && $value == '') {
// for /home
if(wire()->page->image_intro && wire()->page->image_intro->count){
$event->return = wire()->page->image_intro->first()->media->size(1200, 600)->httpUrl;
}
// for other templates
if(wire()->page->image_media_manager && wire()->page->image_media_manager->count){
$event->return = wire()->page->image_media_manager->first()->media->size(1200, 600)->httpUrl;
}
}
});
The Problem is that its only useful at the front-end. We wanted to add the Field as default value to preview it on the Processswire page backend too. Are there any hooks for the Backend aswell?
@rmelchner
Thanks for the example. The hook works everywhere, front- and backend. I think the problem is that when you are editing a page in the ProcessWire admin, wire()->page
does not return the page being edited. You would need to get that page from the ProcessPageEdit
process. Unfortunately I do not find the code how to do this right now...
@rmelchner I'm closing this issue, let me know if the proposed solution does not work.
Hi, we use the Media Manager plugin (https://modules.processwire.com/modules/process-media-manager/) for images in our templates and to output e.g. the
og:image
tag, the syntax{image_media_manager.first.media}
does not work in the default values settings page (I assume because the Media Manager plugin does not return a Processwire PageImage object but a MediaManager object as described here: https://mediamanager.kongondo.com/documentation/frontend-output-of-media-manager-fields/media-manager-objects/).The value
{image_media_manager.first.media.httpUrl}
or{image_media_manager.first.media.url}
also won't work.Is there a way to do this with the provided syntax only or do we need to write a hook?
Thank you!