Showing posts with label Inline and Drupal.settings JS in Drupal. Show all posts
Showing posts with label Inline and Drupal.settings JS in Drupal. Show all posts

Wednesday, July 20, 2011

Inline and Drupal.settings JS in Drupal

<?php  // This add inline JS to the head of the document
 
drupal_add_js('alert("Hello!")', 'inline');


  drupal_add_js("var automatic_logout = true;", 'inline');
  /* Output in the Webpage:
<script type="text/javascript">
var automatic_logout = true;
</script>
  */ 
 

 
// This will add variables in the Drupal.settings object
 
drupal_add_js(array('my_module' => array('my_setting' => 'this_value')), 'setting');
   drupal_add_js(array('contactus' => 
                array('argCustom' => 'custom',
                      'cleanUrl' => 'true',)), 
                'setting');
/* Output: 
<script type="text/javascript">
jQuery.extend(Drupal.settings, 
{ "contactus": { 
"argCustom": "custom", 
"cleanUrl": "true" } 
});
</script>
*/

?>

Followers