I'm stuck on including an external JavaScript file on a custom page. The API service requires the HTML to be formatted as below

<script type="text/javascript" src="//platform.example.com/api.js">
api_key:   [key]

No idea if this can be done the Drupal way. I tried:

// load SDK
drupal_add_js('//platform.example.com/api.js', 'external');
drupal_add_js('api_key:   [key]', 'inline');

But without success. The API_key declaration need to be done inside the first tag that links to the external JS. I know you can add extra parameters like documented on https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_add_js/7.x but this case is not described.


You can try something like

$external_js = array(
  '#markup' => '<script type="text/javascript" src="//platform.example.com/api.js">
    api_key:   [key]

drupal_add_html_head($external_js, 'my_module');
| improve this answer | |

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.