User login

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!");

Resolution

Searched words: 
gmap call css for map calling a gmap view directly does not load js add javascript only if front page drupal // 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 .'markerloader_static.js'); drupal_add_js($path .'icon.js'); module check if on front page drupal hook call on page load drupal_add_js doesn't work call gmap directly

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • You can use Markdown syntax to format and style the text. Also see Markdown Extra for tables, footnotes, and more.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img> <blockquote> <small> <h2> <h3> <h4> <h5> <h6> <sub> <sup> <p> <br> <strike> <table> <tr> <td> <thead> <th> <tbody> <tt> <output>
  • Lines and paragraphs break automatically.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.