As per Drupal's definition "A hook is a PHP function that is named foo_bar(), where "foo" is the name of the module (whose filename is thus foo.module) and "bar" is the name of the hook. Each hook has a defined set of parameters and a specified result type."
hook_theme is one of the most important hook in Drupal and basic purpose of this is to theme output. hook_theme basically returns HTML or it can also specify how a particular render array is to be rendered as HTML.
hook_theme can be used in template.php or in any module file.
In template.php it can be used to theme the theme's template like header.tpl.php. For example:
function mytheme_theme($existing, $type, $theme, $path){
return array(
'mytheme_header' => array(
'template' => 'header',
'path' => $path . '/templates',
'type' => 'theme',
'variables' => array(
'title' => NULL,
'some_text' => NULL,
),
),
);
}
In module file, we can assign html template for any page. For example:
/*
* Returns custom content to Drupal
*/
function my_page_function() {
// Call theme() function, so that Drupal includes the custom-page.tpl.php template
return theme('my_custom_template');
}
/*
* Implement hook_theme().
*/
function custom_example_theme(){
return array(
'my_custom_template' => array(
// file name will be custom-page.tpl.php
'template' => 'custom-page',
),
);
}
I hope this will help someone.
0 Comment(s)