3

There are many tutorials on adding js to themes in Drupal 7, but the examples for Omega Sub Themes seem to omit the part about remote scripts, scope and weight:

In the theme .info file:

scripts[] = js/map.js

So how do I specify remote URL, header or footer, and what weight to assign?

scripts[] = https://maps.googleapis.com/maps/api/js?key=XXX&sensor=false

results in <script src="&amp;muqqwd"></script> and even if it did work, I still need it to be in the header.

2

External javascript files can't be declared inside the theme.info file, unfortunately. Inside your template.php file, you'll have to add something like this:

<?php
  drupal_add_js('https://maps.googleapis.com/maps/api/js?key=XXX&sensor=false', 'external');
|improve this answer|||||
  • The best is to invoke drupal_add_js() from your theme implemtantion of HOOK_preprocess_page(). See drupal.org/node/304255 for more details. – Pierre Buyle Oct 17 '13 at 9:07
0

Try something like:

/**
 * Implements template_process_HOOK().
 */
function template_preprocess_page(&$variables) {

  $element = array(
    '#type' => 'markup',
    '#markup' => '<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?v=3.exp&signed_in=false&libraries=places&key=API_KEY"></script>',
  );

  drupal_add_html_head($element, 'google_maps_js');
}

This is based on this post.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy