0

I am just tried to create a module name mymodule and tried to apply theme to that module in drupal6.

I have added .info file for my module and created mymodule.tpl.php file in my theme folder and enable the module from the admin. But when i access the module through url it returns white page.

My mymodule.module.php file contains

function mymodule_menu() {
  $items = array();

  $items['mymodule'] = array(
    'page callback' => 'mymodule_page',
    'access arguments' => array('access content'),
    'type' => MENU_CALLBACK,
  );

  return $items;
}

function mymodule_page() {
  $result = db_query('SELECT * from node');
  return theme('mymodule', array('output' => $result));
}

function mymodule_theme() { 
  $content =  array(
    'custom' => array(
      'arguments' => array('output' => 'NULL'),
       'template' =>  path_to_theme() . '/mymodule',
      'path' => '/'
     ),
  );
  return $content;
}

I don't know why the theme is not applying to my module. Please help.

anoop
  • 1,604
  • 6
  • 24
  • 50

1 Answers1

1

For what I see the problems are the path and template keys.

From Drupal docs ( http://api.drupal.org/api/drupal/developer%21hooks%21core.php/function/hook_theme/6 ):

path: Override the path of the file to be used. Ordinarily the module or theme path will be used, but if the file will not be in the default path, include it here. This path should be relative to the Drupal root directory.

So you're overriding the module path with /, which should result in the Drupal root folder ( in which there is no mymodule.tpl.php ). Try removing the path key.

Also, the template key should be only the template file name. Docs:

template: If specified, this theme implementation is a template, and this is the template file without an extension.

So try removing the path_to_theme part, as you have to give the template file name and not the full path to the template ( which you are providing using the path_to_theme function ).

Hope this will help!

endorama
  • 498
  • 7
  • 15
  • Yah its worked for me. Currently i can only able to view this in content area of page.tpl.php. How can i change the entire template for a theme? This question i have added here http://stackoverflow.com/questions/16609463/how-can-i-change-the-entire-template-of-the-page-according-to-module-in-drupal6 – anoop May 17 '13 at 12:56