2

I wrote a simple module that uses hook_theme().

/**
* Implements hook_theme().
*/
function test_theme() {
  'upload_page' => array(
  'template' => 'templates/upload_page',
  'arguments' => array(
    'uploadurl' => NULL,
    'options' => NULL,
    'title' => NULL,
    'user' => NULL),
   )
}

I still have an error.

Warning: include(./sites/all/themes/test/templates/upload_page.tpl.php): failed to open stream: No such file or directory

How do I change this path to ./sites/all/modules/test/templates?

1 Answer 1

1

Drupal won't look for the template in a theme path unless

  1. You've added this code to a theme instead of a module or
  2. You've put your module in the theme folder instead of sites/all/modules, and then perhaps moved it once installed (less likely I think).

If you've done either of these I'd advise fixing that problem and putting the code/module where it's supposed to go.

If you're too invested at this point, though, you can use the path argument to hook_theme() to provide a static path to your theme's implementation folder:

'upload_page' => array(
  'template' => 'templates/upload_page',
  'arguments' => array(
    'uploadurl' => NULL,
    'options' => NULL,
    'title' => NULL,
    'user' => NULL
  ),
  'path' => drupal_get_path('module', 'test')
)

The docs I've linked to are for Drupal 6 as I assume from your code that's what you're using; if you're using Drupal 7, the arguments property should be changed to variables.

1
  • Thanks for answer, but I haven't added my code to theme but to module and I haven't moved this code after install. It is possible that it happens because I have theme on the same name what module is?
    – nitek
    Jun 22, 2012 at 8:08

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.