0

I created a module with a hook_theme(). It works fine but when I copy my-custom-template.tpl.php file into my theme folder to customize the override doesn't work. I don't understand what I am doing wrong.

function foo_bar_theme() {
  return array(
    'something' => array(
      'template' => 'my-custom-template',
      'variables' => array(
        'zone' => null, 
        'location' => null, 
        'class' => null),
    ),
  );
}

Can someone help me please? I've checked everything, cleared the cache, checked the spelling, made sure the names are original to not have name clashes.

1

you can try

function foo_bar_theme() {
  return array(
    'something' => array(
      'template' => 'my-custom-template',
      'arguments' => array(),
    ),
  );
}
  • The template name is not correct. – kiamlaluno Sep 14 '12 at 23:42
1

The file outside your module should be named (in your example) something.tpl.php.

  • This is correct: The template file cannot have a name that is too different from the theme name, apart the difference between hyphens, and underscores. Of course, the template name reported in hook_theme() must follow those rules too. – kiamlaluno Sep 14 '12 at 23:42
0

Your template file must be placed in your modules directory or you can use file option see return values for hook_theme here

function foo_bar_theme() {
  return array(
    'something' => array(
      'template' => 'my-custom-template',
      'file'=>drupal_get_path('theme','my_default_theme').'my_custom_template.tpl.php',

      'variables' => array(
        'zone' => null, 
        'location' => null, 
        'class' => null),
    ),
  );
}

you may override theme suggestions in your default theme's template.php you have to write overriding functions like this

function MYTHEME_something($variables){}

you can do this for all theme registry elements(use devel module to see all theme registry) drupal looks for theme implications like let's say that you use grayscale theme:

  • grayscale_something()
  • sites/all/themes/grayscale/something.tpl.php
  • theme_something()

the last theme something assumed that you wrote a theme_something function in your module

  • The template name (my-custom-template) is not correct when the function name is theme_something(). – kiamlaluno Sep 14 '12 at 23:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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