0

I've created a block like this

function mymodule_block_view($delta = '') {
    if($delta == 'myblock') {
        $block['subject'] = 'mytitle';
        $block['content'] = myfunction();
    }
    return $block;
}

but the output is like this:

<h2 class="block-title">mytitle</h2>

I need change h2 to div

<div class="block-title">mytitle</div>

I've tried with _preprocess_block hook but i cant change that tag

could you please help me?

6

1 Answer 1

0

try with the following:

  1. Implement hook_theme_registry_alter to take the templates from your module.

/**
 *  Implements hook_theme_registry_alter().
 */
function mymodule_theme_registry_alter(&$theme_registry) {
  // Defined path to the current module.
  $module_path = drupal_get_path('module', 'mymodule') . "/templates";
  // Find all .tpl.php files in this module's folder recursively.
  $template_file_objects = drupal_find_theme_templates($theme_registry, '.tpl.php', $module_path);
  // Iterate through all found template file objects.
  //test if this page isn't in BO page
  if (!path_is_admin(current_path())) {
    foreach ($template_file_objects as $key => $template_file_object) {
      // If the template has not already been overridden by a theme.
      if (!isset($theme_registry[$key]['theme path']) || !preg_match('#/themes/#', $theme_registry[$key]['theme path'])) {
        // Alter the theme path and template elements.
        $theme_registry[$key]['theme path'] = $module_path;
        $theme_registry[$key] = array_merge($theme_registry[$key], $template_file_object);
        $theme_registry[$key]['type'] = 'module';
      }
    }
  }
}

  1. Copy modules/block/block.tpl.php and past it in templates folder of your module.
  2. Rename it from block.tpl.php to block--mymodule--myblock.tpl.php to change only for your block.
  3. Change the line from <h2<?php print $title_attributes; ?>><?php print $block->subject ?></h2> to <div<?php print $title_attributes; ?>><?php print $block->subject ?></div>
  4. Clear cache.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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