Alter Block render array and add another block's content I am attempting to attach a block to another block via hook_block_view_alter. The source block is a menu_block and the block to be attached is a view block, but the type of block shouldn't matter to the solution.

Here is the code used to attach the block. Assume that block_attached_block is populated with the bid of the block and at the point where I am altering the render array I have a fully rendered block.

function MODULE_block_view_alter(&amp;$data, $block) {
  if (!empty($block-&gt;block_attached_block)) {

    // load the attached block from the database
    $attached_block = db_select('block', 'b')
      -&gt;fields('b')
      -&gt;condition('b.bid', $block-&gt;block_attached_block)
      -&gt;execute()
      -&gt;fetchObject();

    // render the block
    $block_content  = _block_render_blocks(array($attached_block));
    $build          = _block_get_renderable_array($block_content);
    $block_rendered = drupal_render($build);

    // attach the block
    $data['block_attached_block'] = array(
      '#type' =&gt; 'container',
      '#attributes' =&gt; array(
        'class' =&gt; array('block_attached_block'),
      ),
      'block' =&gt; array(
        '#markup' =&gt; $block_rendered,
      ),
    );
  }
}


If I render $data at this point I see the attached block rendered perfectly.

drupal_render($data);


However, when I load the page the attached block is missing. The documentation is pretty light.

My question is how do I get the rendered block to output on the page.
Here is an updated function taking into account some of the various types of blocks that we can attach blocks to.

function MODULE_block_view_alter(&amp;$data, $block) {
  if (!empty($block-&gt;block_attached_block)) {

    // load the attached block from the database
    $attached_block = db_select('block', 'b')
      -&gt;fields('b')
      -&gt;condition('b.bid', $block-&gt;block_attached_block)
      -&gt;execute()
      -&gt;fetchObject();

    // render the block
    $block_content = _block_render_blocks(array($attached_block));
    $build         = _block_get_renderable_array($block_content);

    // create attached block render array
    $block_attached_block = array(
      '#type' =&gt; 'container',
      '#attributes' =&gt; array(
        'class' =&gt; array('block_attached_block'),
      ),
      'block' =&gt; $build,
    );

    // attach the block
    switch ($block-&gt;module) {

      // menu block module blocks
      case 'menu_block':
        $data['content']['#content']['block_attached_block'] = $block_attached_block;
        break;

      // views module blocks
      case 'views':
        $data['content']['#markup'] .= drupal_render($block_attached_block);
        break;

      // block module blocks
      // webform module blocks
      case 'block':
      case 'webform':
        $data['content'] .= drupal_render($block_attached_block);
        break;

      // all other module blocks
      default:
        $data['content']['block_attached_block'] = $block_attached_block;
        break;
    }
  }
}


Thanks Clive for getting me started on the right path.