Search code examples
drupalthemeshook-menu

How to display custom html block in Drupal using theme?


Having some module, defined some url in hook_menu() and need to display there some theme (modules/mymodule/templates/mytheme.tpl.php). How do I show mytheme.tpl.php content on needed url?

function mymodule_menu(){
    $item = array();

    $item['somemenu'] = array(
     'page callback' => 'somemenu_display',
  );

    return $item;
}

function somemenu_display(){
       return WHAT_IS_THIS_FUNCTION('modules/mymodule/templates/mytheme.tpl.php');
}

And it will be good to display only these contents, without and header/footer.


Solution

  • The function is Theme()

    return theme('some_theme_function_template', array('aValues' => $someArray));
    

    You then need to use the theme hook like this:

    function my_module_name_theme() {
        return array(
            'some_theme_function_template' => array(
                'template' => 'mytheme',
            ),
        );
    }
    

    It now searches for mytheme.tpl.php in the root of your module.