How to insert a block into a node or template in Drupal 7?

后端 未结 15 1088
闹比i
闹比i 2021-01-30 01:46

In Drupal 6, it was easy to insert a block into a template with the following code:

$block = module_invoke(\'views\', \'block\', \'view\', \'block_name\');
print         


        
相关标签:
15条回答
  • 2021-01-30 02:09

    This work for me:

    98 is the id of the block

    $block =block_load('block',98);
    $output = drupal_render(_block_get_renderable_array(_block_render_blocks(array($block))));
    print $output;
    
    0 讨论(0)
  • 2021-01-30 02:11

    This worked for my Drupal 7 , URL: admin/structure/block/manage/addthis/addthis_block/configure NOTE:delta and module name present in the url itself

    $addblock = module_invoke('addthis','block_view','addthis_block');
    print render($addblock['content']);

    More information can be found on http://technarco.com/drupal/insert-block-node-or-template-drupal-7

    0 讨论(0)
  • 2021-01-30 02:13

    Improving wrburgess' answer, you can do it in one line...

    <?php print drupal_render(_block_get_renderable_array(_block_render_blocks(array(block_load('module_name', 'block_delta'))))); ?>
    

    So for example, I use block number 6...

    <?php print drupal_render(_block_get_renderable_array(_block_render_blocks(array(block_load('block', '6'))))); ?>
    
    0 讨论(0)
  • 2021-01-30 02:16

    This appears to be the solution for inserting blocks into templates for Drupal 7, but it seems a bit clunky and I have no idea about impact on performance:

    $block = block_load('views', 'block_name');      
    $output = drupal_render(_block_get_renderable_array(_block_render_blocks(array($block))));        
    print $output;
    

    If anyone has a better procedure, please do add.

    0 讨论(0)
  • 2021-01-30 02:17

    For some reason render() doesn't work for me, but this does:

    <?php
        $block = module_invoke('block', 'block_view', '1');
        echo $block['content'];
    ?>
    
    0 讨论(0)
  • 2021-01-30 02:19

    Just tested this in drupal 7 and it works:

    $bloqueServicios = module_invoke('views', 'block_view', 'servicios-blo_home');
    print render($bloqueServicios);
    

    Good luck!

    0 讨论(0)
提交回复
热议问题