Last active
          December 11, 2015 11:48 
        
      - 
      
- 
        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.
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | 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