2

Is there any way by which i could assign a template to my custom module.I heard it may be possible.I tried out with the hook_theme function.My hook_theme looks something like this

    function special_theme() {
return array(
    'special' => array(
      'template' => 'special',
      'arguments' => array('link' => NULL),
    ),
  );
}

I do have a special.tpl.php file in my module folder.But the tpl file is not called.Its my default template that is been shown as output.Could someone please help me in the right direction.would be very helpful.

Nibin
  • 3,922
  • 2
  • 20
  • 38

1 Answers1

1

What you define via hook_theme() is an available template, not one that is automatically used. In order to use that template you need to call theme('special', $link);.

It is also advised to avoid using simple words for theme names to avoid collisions ( try mymodule_special instead ).

Also note (though basic), that you also need to print the return value of theme(), it does not get automatically printed. So for instance,

print theme('special', $link);
Nick Andriopoulos
  • 10,313
  • 6
  • 32
  • 56
  • sorry to ask,where should i be calling this theme('special', $link);. – Nibin May 17 '13 at 12:02
  • wherever you would want to output your `special` themed `$link` -- sorry for being cryptic but that is too general. – Nick Andriopoulos May 17 '13 at 12:03
  • tanx.now the special.tpl.php page is called.I do had a default.tpl.php file that i used as a default template.I find that now both of the tpl contents are being shown.I just made an echo in the special.tpl.php page ..The echoed text along with the contents of the default.tpl.php file is being shown.why is it that both the tpl file are shown..? – Nibin May 17 '13 at 12:16