2

I am using Drupal 6, and I have created a custom module which is in the "sites\all\modules\custom" folder; in the same folder there is also the custom.tpl.php file.

I want to place the custom.tpl.php file in the theme folder.

Here is my code:

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

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

  return $items;
}

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

function custom_theme() {
  return array(
    'custom' => array(
      'arguments' => array('output' => NULL),
      'template' => 'custom',
     ),
  );
}

function template_preprocess_custom(&$variables) {}
0

2 Answers 2

1

Well you can place in the theme folder or you can leave it in the module. Drupal will look in both places. So if your implementation of hook_theme is a template, Drupal will look for the following files:

  • themes/bluemarine/custom.tpl.php
  • modules/custom/custom.tpl.php

If you read the documentation for hook_theme you'll get your answer for the question when you get to the path key:

path: [...] Ordinarily the module or theme path will be used [...]

5
  • I can't get this to work, there is a missing step somewhere. It always uses the module template file.
    – Toby Allen
    Aug 15, 2013 at 22:27
  • did you clear the theme cache?
    – Max
    Aug 16, 2013 at 7:49
  • I cleared all caches.
    – Toby Allen
    Aug 16, 2013 at 7:51
  • Did you try sathishkumar addition? You have to tell the theme engine where your file is located, otherwise he will have the behavior in my answer. Paste the new code you tried. And what I don't understand is why do you need to keep 2 versions of custom.tpl.php one in your module and one in your theme. It should stay in your module, not in the theme folder.
    – Max
    Aug 16, 2013 at 12:04
  • 1
    Thanks @max the whole point of the exercise is that I don't need to tell drupal where the file is located it should try the module or the theme folder at the moment is only trying the module folder unless I explicitly tell it which is a bit silly.
    – Toby Allen
    Aug 16, 2013 at 17:45
-1

Please give path key in theme registry.

function custom_theme() {
  return array(
    'custom' => array(
      'arguments' => array('output' => NULL),
       template' =>  path_to_theme() . '/custom',
      'path' => '/'
     ),
  );
}
1
  • This just makes it check the root directory for the template?
    – Toby Allen
    Aug 16, 2013 at 17:48

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.