Hi,

I am using following code to theme forms in my module:

Mymodule_theme($existing, $type, $theme, $path) {
return array(
'mymodule_form' => array(
'arguments' => array('form' => NULL),
'template' => 'registration',
);
}

Then i can theme this form by placing a template file "registration" in my module itself.

But, i have got some hook in my module that doesn't have a form, its just a simple hook:

Mymodule_cpsuccess(){
drupal_set_message('hi');
}

I want to specify a template for this hook and want to theme it using that template, please suggest me a way to achive this.

Regards,
Kul.

Comments

justsomeguy.com’s picture

Hi Kul:

I'm not entirely sure what you are trying to do here, but if you just want to make your function theme-overrideable (so you can implement phptemplate_cpusucess() later to override the way it looks) you can just add another entry to your hook_theme's return data:

Mymodule_theme($existing, $type, $theme, $path) {
return array(
  'mymodule_form' => array(
      'arguments' => array('form' => NULL),
      'template' => 'registration',
  ),
 'cpusuccess' => array(
      'arguments' => array()
  )
);

Then, somewhere in your code, you add your theme callback:

function theme_cpusuccess() {
  drupal_set_message( t('woo hoo - here is the message from a themed function') );
  return t('It worked - huzzah');
}

And then you would modify your function like this:

Mymodule_cpsuccess() {
  return theme( 'cpusuccess' );
}

You could, of course, pass the message as an argument if that's the sort of functionality you are looking for.

I hope that was helpful.

Cheers,

Steve