Dynamically rendering dynamically rendered pages

Looking for advice…and a question.

My question: Is there a way to intercept the html, from a controller, before it is fully sent to the browser? Ex: After all containers, blocks, etc. are rendered.

Background…i have page templates which are used in page types. Users, using the “output” option can modify how the pages render and what content is included. I generate one apartment container/section for each apartments that is assigned to that page. Everytime the page is loaded, i need to validate that apartment has a container, if not, create one. If an apartment has been removed from the property, i need to remove it from the patch.

The catch is that i need the page to be fully in-place editable after it’s rendered so that people can make changes to it on the fly.

So basically i want to intercept the page, add/remove containers/blocks as needed, then render it.

Any recommended approaches?

You may be able to do something by handling and responding to events

Another option would be to override or extend the Area class. This class loops through and outputs the blocks in an area.

If you have a bespoke theme, declare and ExtendedArea class which extends the Area class. Then in the page templates, use the ExtendedArea class for the Main area of the theme templates.

That would provide a point at which you can intercept and modify the way blocks are output to whatever extent you like.

John those are great ideas Let me think about that.