CHtml VS CClientScript

Hello,

I want to properly include my assets in my application, but I don’t get the difference between CHtml->cssFile() and CClientScript->registerCssFile().

I understand that the CClientScript methods allow to compress assets in a single one. But is that all ?

  1. Can someone explain me what is the real advantage to use one or the other ? And in which situation ?

  2. Is CClientScript using the CHtml methods to render the tags ?

Thanks a lot !

Maxime :)

  1. CClientScript->registerCssFile registers a script independent of where it is called (controller, widget, view…)

See this topic

  1. Yes, CClientScript::registerCssFile() internally uses CHtml::cssFile

Thanks a lot Joblo !

I understand now that you can add a script from anywhere in the code with CClientScript. And that’s a great solution !

One last question : What is the right solution to display assets that are not in widget or other ? (Assets that are in the layout and unique for the application)

Is it to use Chtml or CClientScript ?

Thanks,

Maxime.

Then keep it simple, and use regular html <link> and <script> tags in your layout. I can’t see any benefit of using clientScript here. (It doesn’t combine/compress/minify assets.)

Thank you :)