Skip to content

Instantly share code, notes, and snippets.

@ss81
Last active December 11, 2015 11:48
Show Gist options
  • Save ss81/4596527 to your computer and use it in GitHub Desktop.
Save ss81/4596527 to your computer and use it in GitHub Desktop.
Embed Drupal block region into node page. Snippet to insert or embed Drupal block region into a node template.
YOUR_THEME.info:
...
regions[BLOCK_REGION_NAME] = Block region name
...
template.php:
<?php
/**
* Implements template_preprocess_node().
*/
function YOUR_THEME_preprocess_node(&$vars) {
// Add 'After node' block region inside node.
if ($block_region_name = block_get_blocks_by_region('BLOCK_REGION_NAME')) {
$vars['BLOCK_REGION_NAME'] = $block_region_name;
}
}
?>
node.tpl.php:
<?php if ($BLOCK_REGION_NAME): ?>
<div class="blablabla">
<?php print render($BLOCK_REGION_NAME); ?>
</div>
<?php endif; ?>
To get Context module blocks:
<?php
// Get the context blocks for the sidebar_second region.
$reaction = context_get_plugin('reaction', 'block');
$vars['BLOCK_REGION_NAME'] = $reaction->block_get_blocks_by_region('BLOCK_REGION_NAME');
?>
(c) http://kahthong.com/2012/08/embed-drupal-block-region-node-page
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment