0

I am building a module that contains a route and a controller that only renders a specific theme region, without any surrounding HTML.

How can I load and render the region programmatically within the controller output method?

The region output from the controller contains one or more blocks and the entire region needs to be embedded on another site. The site will retrieve the markup using a custom route (e.g. example.com/partials/header or example.com/partials/footer).

I don't know which blocks are going to be in the region; the list of blocks in the region is not hard-coded in the module.

2

Using the block.repository service you can get an instance of the BlockRepository class. You can then call the getVisibleBlocksPerRegion method on it which will return an associative array BlockInterface[][] (first key is the region name, second key is the block ID).

You will probably need to change the active context if some of these blocks only appear certain conditions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.