[development] php and js in a programmatic block
jeff at ayendesigns.com
jeff at ayendesigns.com
Sun Nov 28 16:04:36 UTC 2010
Ah, gotcha. Not sure this is more intuitive than the other way, but if
it's common practice then so be it :)
Thanks!
On 11/28/2010 11:02 AM, Steve Ringwood wrote:
> 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, jeff at ayendesigns.com 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
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.drupal.org/pipermail/development/attachments/20101128/d94550a4/attachment.html
More information about the development
mailing list