I'm trying to create a custom Drupal 7 module where it renders a custom page template. I want the data on /animals and /animals/getanimal to be in a custom HTML template.
After much searching and few successes, I've found that hook_preprocess_html works and that I can stop Drupal from loading the default template, but I'm struggling to pass data to my templates from the menu hook.
Is there a way to pass data from the menu hook to hook_preprocess_html, or is there another way where I can load my own custom template from the URLs in my custom module?
/** * Implements hook_menu() * @return mixed */ function animal_farm_menu() { $items['animals'] = array( 'title' => 'Discover animals', 'page callback' => 'getDiscover', 'page arguments' => array(), 'access callback' => TRUE, 'type' => MENU_NORMAL_ITEM, 'menu_name' => 'main-menu', ); $items['animals/getanimal'] = array( 'title' => 'all animals', 'page callback' => 'getAnimal', 'page arguments' => array(), 'access callback' => TRUE, 'type' => MENU_NORMAL_ITEM, 'menu_name' => 'main-menu', ); return $items; } function getDiscover() { $result = ['cat','dog','monkey','cow']; return $result; } function getAnimal() { $result = ['cat','dog','monkey','cow']; return $result; } /** * Implements hook_preprocess_html(). */ function animal_farm_preprocess_html(&$vars) { $node = menu_get_object(); $path = current_path(); // echo $path; // Add a new theme suggestion when viewing node's of mynodetype. if ($path == 'animals') { $vars['theme_hook_suggestions'][] = 'html__mynodetype'; $vars['data'] = [1,2,4,'monkey']; } if ($path == 'animals/getanimal') { $vars['theme_hook_suggestions'][] = 'animal_farm_discover'; $vars['data'] = [1,2,4,'monkey']; } } /** * Implements hook_theme(). */ function animal_farm_theme($existing, $type, $theme, $path) { $theme = array(); //Add our templates/html--mynodetype.tpl.php to the theme registry $theme['html__mynodetype'] = array( 'template' => 'html--mynodetype', 'path' => drupal_get_path('module', 'animal_farm') . '/templates', ); return $theme; }