"create a custom template file for a custom block in drupal" Code Answer

4

this seems to work fine.

//implementation of hook_block_info
function mymodule_block_info() {
  $blocks = array();
  $blocks['myblock'] = array(
    'info' => t('my block title'),
  );

  return $blocks;
}

//implementation of hook_block_view
function mymodule_block_view($delta='') {
  $block = array();

  switch($delta) {
    case 'myblock' :
      $variables = array(); //do stuff here
      $block['content'] = theme('mytemplate', $variables);
      break;
  }
  return $block;
}


//implementation of hook_theme
function mymodule_theme() {
  return array(
    'mytemplate' => array(
      'variables' => array(),
      'template' => 'mytemplate',
    ),
  );
}
By akshay7692 on August 27 2022

Answers related to “create a custom template file for a custom block in drupal”

Only authorized users can answer the Search term. Please sign in first, or register a free account.