Dynamic javascript inclusion

Is there a way to dynamically declare which javascript files to include in the <head> section of the layout file?

I have a login.js that contains form validation and login specific javascript that i want to place in the <head> section of the layout but I don’t want it to be included on every page.

I know I can just write a bunch of if…else in the layout file to check for the view file and include the needed files but this is so nasty and will become unmaintainable very quickly. The ideal scenario would be for each view file to control which js files to include.

Any other idea? If only Yii layout supports multiple content sections.

Found my solution by using CClientScript->registerScriptFile() function by digging through yii source code.

Hi Kenny Ma…

welcome to the forum…

I’m glad you resolved by yourself the first problem you posted here…

digging through yii source code… is the best way to learn the framework (IMO)…

Thanks.