Calling a GMap View from a theme, the hacky way
OK, so the situation is that we have a custom front page, page-front.tpl.php and we want to call a GMap view.
GMaps does not like to be shown through a view called directly by a theme.
We tried every possible way we could think of including drupal_add_js() in modules and the page-front.tpl.php and nothing worked.
Ultimately, we put the two <script > javascript lines that were missing (using the sophisticated technique of viewing source on the view/map page that worked and the home page that didn't).
Things we learned: drupal_is_front_page does NOT work from a module (at least, not randomly thrown into a module).
This didn't work in template.php either even though drupal_is_front_page did work there.
if (drupal_is_front_page()) {
drupal_set_message("SHOW ME!");
// maybe we should try to call this only on pages that have maps
// but almost every page has a map
$path = drupal_get_path('module', 'gmap') .'/js/';
drupal_add_js($path .'icon.js');
drupal_add_js($path .'markerloader_static.js');
}
drupal_set_message("No, show me!");
Comments
Post new comment