I have created custom block in my custom module. I have created block template file into module templates folder. Custom block content coming successfully as per given in block__MODULENAME__dummmy_xyz.tpl.php file. I have only added following code into my block tpl file:

<div class="wrapperDummy">Hello</div>

But it is coming with block parent div's, Block id and block-inner tag. I dont want to show those extra div's. Following is the hook_theme which I have in my module file:

 * Implements hook_theme().
function MODULENAME_theme($existing, $type, $theme, $path) {

    $items = array();

    $items['MODULENAME_dummmy_xyz_block_theme'] = array(
        'type' => 'theme',
        'path' => drupal_get_path('module', 'MODULENAME') . '/templates',
        'template' => 'block__MODULENAME__dummmy_xyz',
        'variables'  => array()
    return $items;

I am rendering block into tpl using,

$block = block_load('MODULENAME','dummmy_xyz');
print drupal_render(_block_get_renderable_array(_block_render_blocks(array($block))));

block.tpl.php code:

<?php print $outer_prefix . $inner_prefix; ?>
  <?php print render($title_prefix); ?>

  <?php if ($title): ?>
    <h2<?php print $title_attributes; ?>><?php print $title; ?></h2>
  <?php endif; ?>

  <?php print $content_processed; ?>

  <?php print render($title_suffix); ?>
<?php print $inner_suffix . $outer_suffix; ?>

Kindly guide me.

  • Is that D7 or D8? In D7 the block's parent/wrapper element is <section> not <div>.
    – mchar
    Nov 15 '16 at 13:11
  • It is D7. I have updated description again. Please have a look once.
    – Reshma
    Nov 15 '16 at 13:40
  • Is the template name even in the list of suggestions when being preprocessed?
    – Kevin
    Nov 15 '16 at 17:14
  • Yes, I taken it from list of suggestions.
    – Reshma
    Nov 16 '16 at 7:08

_block_get_renderable_array function render default block theme where I couldn't remove parent element, So I made it by using module_invoke function:

$block = module_invoke('custom_module_name', 'block_view', 'block_name');
              print render($block['content']);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.