How to apply a theme to a Drupal function?

71 views Asked by At

I have a Drupal 7 function named _home() that is called by the home URL.

In this function I want to generate HTML output and, returning it. I need to show the resulting HTML to the user. Actually I embed HTML tags (div, tables,b...) inside the function and return to the user. It runs but I think there must be a better way to do it, maybe using templates or themes. Is there a way to apply a template to the _home function even if it is not a node/another Drupal object?

1

There are 1 answers

0
Ashu On BEST ANSWER
if the "home" url is being created using modules then the following might be useful for you.

In your module file create
function modulename_theme($existing, $type, $theme, $path)
   {
   $theme_hooks = array(
    'home' => array(
      'template' => 'home',//name of template file will be home.tpl.php
      'path' => $path . '/templates',
      'variables' => array(
      ),
    ));
     return $theme_hooks;
    }
    //As _home is the callback function for "home" url
    function _home($node)
    {
    return theme('home', array('node' => $node));
    }



Now under your module create a templates folder & in that create home.tpl.php & place your html in that file..