0

I'm trying to create a theme function, with a template:

/**
 * Implements hook_theme().
 */
function mycustomtheme_theme($existing, $type, $theme, $path) {
  return array(
    'custom_function' => array(
      'template' => 'my-template',
    ),
  );
}    

The my-template.tpl.php file is in the module directory and it works, I have added this to my page.tpl.php:

<?php print theme('custom_function', array()); ?>

I've tried to copy that template on my theme, but it doesn't work, Drupal always reads the module template, not the theme.

Have I forgotten something?

2 Answers 2

0
/**
 * Implements hook_theme().
 */
function mycustomtheme_theme($existing, $type, $theme, $path) {
  return array(
    'custom_function' => array(
      'template' => 'my-template',
      'path' => path_to_theme(),
    ),
  );
}

OR for the my-template.tpl.php file is in the module directory

/**
 * Implements hook_theme().
 */
function mycustomtheme_theme($existing, $type, $theme, $path) {
  return array(
    'custom_function' => array(
      'template' => 'my-template',
      'path' => drupal_get_path('module', 'mycustomtheme'),
    ),
  );
}
-1

I think if you want the theme to pick up the template you need to put it in the theme folder not a module folder. I doubt very much that the theme system goes looking elsewhere for template files.

3
  • As I wrote, I've copy the template in my theme folder.
    – arrubiu
    May 4, 2015 at 14:44
  • You can't have it in two places at once.
    – Darvanen
    May 4, 2015 at 23:30
  • Every module works in this way: it add a theme function, the "original" template is inside the module and I can copy this template, without renaming it, in my theme. Or not?
    – arrubiu
    May 5, 2015 at 5:53

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.