I need <script> in header to define a JavaScript variable (var dates={...};) which is to be used from a .js script.
It should be preferably in header and not inside jQuery(function($){...}) not to hide the variable from using it by my .js script.
Can it be done in any other way than modifying the layout?
Yii::app()->clientScript->registerScript($script_source, CClientScript::POS_HEAD)in the controller?$(function() { window.dates = ... ; })(though you might want to think about a more unique name for it).Yii::app()->clientScript->registerScript($scriptId, $scriptSource, CClientScript::POS_HEAD)and for me at least, on Yii 1.1.13, it will not be wrapped insidejQuery(). That would happen onCClientScript::POS_READY.