I am loading a widget in my page that requires a js library to be included, the problem is that registerScript() always throws the scripts at the start of the script tag.

So I tried to use CClientScript::POS_LOAD, but I can't seem to get the scripts added that way at all. Is there a way to load to the end of the script tag?

Are you including a js file or a piece of js code?

For the former, check API for registerScriptFile; and the latter for registerScript.

apologies, wrong method. I meant registerScriptFile:

VsMootoolsWidget.php (extends CWidget)

    // Load Mootools js library

    $mootoolsJs = dirname(__FILE__).DIRECTORY_SEPARATOR.'js'.DIRECTORY_SEPARATOR.'mootools-1.2.0-core.js';

    if ( !$clientScript->isScriptFileRegistered('mootools-1.2.0-core.js') )


      $mootoolsJsFile = Yii::app()->getAssetManager()->publish($mootoolsJs);

      if (!$mootoolsJsFile == NULL)


        $clientScript->registerScriptFile($mootoolsJsFile, CClientScript::??POS_HEAD_END??);



the problem is that in the main layout i include mootools from the theme folder, i want to make sure that I only include one of them if I am including a mootools widget.

Please check the API for registerScriptFile. You can't use POS_LOAD with this method.

Yes, I understand that. I was hoping to have a little more control over where the script file is put in the script block.

I end up with something like this:

(mootools-core.js in the layout/main.php can never be loaded before the registerScriptFile(accordion stuff) takes place)

the accordion.js requires mootools.js before it. so it seems like a good solution would be to create a POS_HEAD_START and POS_HEAD_END.


        <link rel="stylesheet" type="text/css" href="/VS_Yii/assets/bc93ce71/vs-mootools-accordion.css"/>

<script type="text/javascript" src="/VS_Yii/assets/6d015700/vs-mootools-accordion.js"></script>

        <meta http-equiv='Content-Type' content='text/html; charset=utf-8' />

        <script type='text/javascript' src='/VS_Yii/themes/default/js/mootools-1.2.0-core.js'></script>

        <script type='text/javascript' src='/VS_Yii/themes/default/js/vs-mootools-basic.js'></script>


The script tags inserted by Yii is right before the <title> tag. So you can insert your own js file either before or after that.

thanks for the help  ;D, the documentation should be updated to reflect this

"CClientScript::POS_HEAD : the script is inserted in the head section."


"CClientScript::POS_HEAD : the script is inserted in the head section and before the title tag."

added to bug tracker as minor