Including dynamic javascript

I have a view that needs to display a few dynamic javascript variables in a script tag, they are then picked up by some included js files.

What is the best way of doing this?

Thanks for your help



    'initMyJavascript',   // Identifier for this snippet

    "myJSVar={val1: $something, val2: $somethingEls, val3: 'somethingStatic'};",


); ?>

The last argument defines, where your code is inserted.

EDIT: Forgot the <?php …

Thanks Mike, that’s great.