Skip to content

Instantly share code, notes, and snippets.

@robdecker
Last active November 2, 2019 02:09
Show Gist options
  • Save robdecker/e651ca6c6b4d3c665563 to your computer and use it in GitHub Desktop.
Save robdecker/e651ca6c6b4d3c665563 to your computer and use it in GitHub Desktop.
[Get Drupal blocks and Context blocks to display elsewhere (ex. in a node.tpl.php)] #d7
<?php
function _mytheme_blocks_by_region($region) {
$context_blocks = array();
$block_blocks = array();
// Blocks that are assigned to the region using Context
if (function_exists('context_get_plugin') && $context = context_get_plugin('reaction', 'block')) {
if ($context_block_list = $context->block_list($region)) {
// Workaround the $context->block_get_blocks_by_region() issue.
// See https://drupal.org/node/966768
$fixed_context_block_list = _block_render_blocks($context_block_list);
$context_blocks = _block_get_renderable_array($fixed_context_block_list);
}
}
// Blocks that are assigned to the region using the blocks interface
if ($blocks = block_get_blocks_by_region('content_bottom')) {
$block_blocks = $blocks;
}
return array_merge($context_blocks, $block_blocks);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment