How to modify page contents within a package?
Permalink
In concrete5.6 we could use the "on_page_output" event or alternatively combination of "on_before_render" and "on_render_complete" to modify the page output in packages.
I believe neither of these methods no longer work. The first one would be the obvious one to use but as currently in the core code, this event does not let us modify the output. It only fires and we can do some other stuff when it hits that event. This line shows you that after the event is fired, the view class does not replace the contents with the resulting content:
https://github.com/concrete5/concrete5-5.7.0/blob/d7ac3892ffc7145189...
Is this an oversight or is there an alternative way of doing this?
Sure, we could modify the contents right there, print it out there and then exit but it feels very wrong. And would also prevent any other packages from firing up.
It also seems that this event is fired for all the views during the page request, including block views. Although, we can of course check that the event object passed to the callback has the "contents" argument set to it, I'm not sure if it's conceptually correct to fire the "on_PAGE_output" event also for block views and possibly other views as well...
EDIT:
And don't get me wrong above, I think it is very useful if we could also modify the block output but I just think the event name is not correct in that context.
I believe neither of these methods no longer work. The first one would be the obvious one to use but as currently in the core code, this event does not let us modify the output. It only fires and we can do some other stuff when it hits that event. This line shows you that after the event is fired, the view class does not replace the contents with the resulting content:
https://github.com/concrete5/concrete5-5.7.0/blob/d7ac3892ffc7145189...
Is this an oversight or is there an alternative way of doing this?
Sure, we could modify the contents right there, print it out there and then exit but it feels very wrong. And would also prevent any other packages from firing up.
It also seems that this event is fired for all the views during the page request, including block views. Although, we can of course check that the event object passed to the callback has the "contents" argument set to it, I'm not sure if it's conceptually correct to fire the "on_PAGE_output" event also for block views and possibly other views as well...
EDIT:
And don't get me wrong above, I think it is very useful if we could also modify the block output but I just think the event name is not correct in that context.
Created a pull request here:
https://github.com/concrete5/concrete5-5.7.0/pull/1689...
https://github.com/concrete5/concrete5-5.7.0/pull/1689...
That way the event (and this would work with multiple) will fire and return its content properly. Something like that.
Not really on the radar at the moment but we'd totally take a pull request for it and get it into 5.7.3.