Jeff

    You still want to drupal_add_js(),   but instead of one call you want two.

    The first is to add your mymodule.js

    The second is to do something like

  $settings = array(
    'MyModule' => array(
        'value1' => 'some value',
        'value2' => 'some other value'
     )
  );

  drupal_add_js( $settings, 'setting' );

  You also need to modify mymodule.js to use the values something like

        var settings = Drupal.settings.MyModule;
        // Now you can use
       // settings.value1 and settings.value2

   (of course you need to change MyModule to your actual module name and I 
would suggest more meaningful names than value1 and value2)

Nevets


On 11/28/2010 9:43 AM, [email protected] wrote:
Nothing confuses me faster than mixing php and js (and especially escaping the 
quotes). In this case, my confusion is the concept and not the gobblygook.


I have a module invoking hook_block, and a function that creates and returns 
the block content. In this function I invoke drupal_add_js to gather the 
contents of ./mymodule.js


So far so good. However, the js needs to be dynamic...there are two function 
values that need to be embedded in it. I'm thinking that with this being the 
case, drupal_add_js might not be the way to go (back to escaping quotes), but 
wanted to poll first for best practice, since I'll be contributing this module.


Thanks,

Jeff



Reply via email to