Why is my custom theme template not found? In my theme's template.php file, I defined a new theme hook using hook_theme():

function MYTHEME_theme() {
  $hooks = array(
    'custombody' =&gt; array(
      'template' =&gt; 'custombody',
      'variables' =&gt; array(
        'content' =&gt; array(
          'body' =&gt; '',
        ),
      ),
      'path' =&gt; drupal_get_path('theme', 'MYTHEME') . '/templates/custom',
    ),
  );

  return $hooks;
}


I also placed a file named custombody.tpl.php under templates/custom.

But I can't get this template working. It's not found from Drupal. I keep getting this warning in the log:


  Theme hook custombody not found


Details:

I am trying to use this template to style the body part of HTML emails. I'm using Swift Mailer to send HTML emails and I want to theme the body part with my custom theme. There is no problem on the swiftmailer part.

Normally swiftmailer.tpl.php prints the body text as it is:

&lt;?php print $body; ?&gt;


I've changed this in my own implementation of swiftmailer.tpl.php in my theme folder like that:

&lt;?php print render($body); ?&gt;


And I'm sending a render array as $body, instead of a string, what normally would be expected.

The array I'm sending is:

$variables['body'] = array(
  '#theme' =&gt; 'custombody',
  '#content' =&gt; array(
    'body' =&gt; 'Actual body text here',
  ),
);


What am I missing, that my custombody template is not being found?

UPDATE:

I also created a theme_custombody() function in my template.php file to test it, but it also doesn't work.

function theme_custombody($variables) {
  return 'TEST';
}
Try something like this:

function mytheme_preprocess_page(&amp;$variables, $hook) {
  $variables['theme_hook_suggestions'][] = 'custombody';
}


to add a theme hook suggestion a template called 'custombody.tpl.php'.

However it sounds like what you really want to do might be to render the $body directly, before it gets passed to the default template. In that case you'd use a process or preprocess function to do that directly instead of doing it in the template itself.