I am developing a custom module and I need to implement a theme. The result of my code below is that the code inside the block does not print because Drupal can't find the theme. I'm using hook_theme() and I'm not sure what I am missing.

Directory structure

directory structure for my module

jsblock.module code

 * Implements hook_theme().

function jsblock_theme($existing, $type, $theme, $path){
  return array(
      'jsblock_custom_theme' => array(
          'variables' => array('content' => NULL),
          'template' => 'panels_pane__block__jsblock_jsblock',
          'path' => drupal_get_path('module', 'jsblock') .'panels_pane__block__jsblock_jsblock',

I've been able to print the block by dropping the the file in the theme templates folder, but not when it is inside the module directory. Can someone please tell me what is wrong with my code?

1 Answer 1


From the naming of your module and template file, I suppose you want to add a template for a custom block returned by your module.

The reason, that your template is found by adding it to the theme is not that you implemented hook_theme() in your custom module, but the way you named the template. It is found by the theme registry's template suggestions used for the block within your panels pane.

If you want your own theme hook jsblock_custom_theme to be applied to the block, you will have to add the theme hook to your block output by using the theme() function. An abstract example:

 * Implements hook_block_view().
function jsblock_block_view($delta='') {
  $block = array();

  switch($delta) {
    case 'jsblock_jsblock':
      $variables = array();

      // Prepare your block variables here.

      $block['content'] = theme('jsblock_custom_theme', $variables);

  return $block;

Some further suggested checks/improvements:

  • Check your template path: Keep in mind that drupal_get_path returns a path without trailing slashes. You will have to add a / to your path.
  • Place your template in a theme subfolder to keeping a cleaner module structure.
  • Don't name the template like the natively used template suggestions to avoid collisions while the theme tries overriding templates.

Your Answer

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

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