Here's my .module code:

 * Implements hook_theme_registery_alter()
function popover_theme_registery_alter(&$theme_registery) {
    $theme_registery['popover'] = array(
        'template' => drupal_get_path('module','popover'). '/popover.tpl.php',
        'type' => 'module',

I'm having some plain html elements in the tpl.php file so that might be not good? or do I have to call this hook somewhere? what's wrong?

  • Just to clarify, are you trying to declare a theme function, i.e. to be called like $output = theme('popover', array(/* some args */));, that uses a template file for it's output?
    – Clive
    Commented Apr 12, 2012 at 15:44
  • I want my module to output the html content instead of just putting it at the end of my module after I close php with ?>, I want to us a template and this is my try of doing it. So I guess this only generates a renderable array? I need to Implement a function to generate the output?
    – FLY
    Commented Apr 12, 2012 at 15:47

1 Answer 1


I'd imagine you should be using hook_theme() instead of hook_registry_alter() to define your theme function:

function MYMODULE_theme() {
  return array(
    'popover' => array(
      'template' => 'popover',
      'variables' => array('var1' => array(), 'var2' => '')

Then you can call it from anywhere (including a page callback, which I think is where you're trying to return this from given your comment above):

$output = theme('popover', array('var1' => $var1, 'var2' => $var2));

In the popover.tpl.php file in your module's root folder you'll have access to the variables $var1 and $var2, which will be the vars you defined/passed into the theme function.

Then you can build up your HTML as you need.

  • Thanks that seams logic I'll try that now. I won't be needing a page callback ( I think ) since it can just run when the module is enabled. But yes this is what I was looking for.
    – FLY
    Commented Apr 12, 2012 at 16:01

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.