I am learning how Flarum is architectured and I set myself the task to add a <meta>
tag to a discussion post if the discussion title contains "blah"
This is what I have so far:
(new Extend\Frontend('forum'))
->content(function(Document $document, Request $request) {
// How would I get the Discussion being loaded from the $document ?
// below code doesn't work because `title` isn't filled yet for some reason
if (substr('blah', $document->title) != false) {
$document->meta['hello'] = 'blah';
}
// Or how could I get the id of the discussion being loaded? Or the author?
})
After digging around in the internals I've discovered the content
callback above is executed BEFORE the Discussion document is loaded.
![
If I add a debug statement in Flarum\Frontend\Frontend@document
method and print out the $document
value when it is populated you can see it then has the title, and the payload of the Discussion being loaded (which is exactly what I want - but I can't get access to it because it's loaded AFTER the extend)
![
So it seems like the content
when extending via (new Extend\Frontend('forum'))
is executed BEFORE the final route data document/payload is loaded.
Is there a way to fix this, so that anything added to ->content()
extender is added to the very end - so essentially giving developers the ability to get access to the full array of document data that is relevant to the page being loaded? E.g. Discussion, Tag, or any of the route document.