1

I've defined a route to a custom controller, which returns a render array to define its content. By default, this content gets rendered entirely inside the main content region of the page: what I want is to have different parts of it rendered to different regions.

I've tried specifying the region (e.g. '#region' => 'content_intro') in the relevant sub-arrays for different elements, but they are still output to my main content region.

I've also then tried adding the following to the base definition of the returned render array:

$content = array(
  '#type' => 'page',
);

This does then allow me to successfully specify the region for placing individual elements. However, other standard elements placed in page regions - specifically, a navigation menu block - are then not output.

How would I best go about having my controller add its content to regions, while still retaining elements placed by other systems?

1 Answer 1

1

The normal way to do this is to provide the main content in a controller and the additional content in block plugins.

If you don't want to use blocks and the block layout for this task (what you really should do!), and want to solve this in code, you can use a preprocess hook to add content your module provides in a function (procedural or static, not a controller) to a region.

1
  • The block plugin approach has worked nicely - thanks for the guidance.
    – lyserge
    Commented May 4, 2016 at 8:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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