CHtml::cssFile

When I use the cssFile helper function to insert CSS files, they don’t get separated by line breaks.

For example:


<?php echo CHtml::cssFile('/css/reset.css', 'all'); ?>

<?php echo CHtml::cssFile('/css/style.css', 'all'); ?>

results in:


<link rel="stylesheet" type="text/css" href="/css/reset.css" media="all" /><link rel="stylesheet" type="text/css" href="/css/style.css" media="all" />

It should output on two seperate lines.

That’s common PHP behavior. Check this:


<?php echo "a" ?>

<?php echo "b" ?>

Besides that i don’t really understand why this should matter … :)

Oh ok lol. It’s just to make the html output look more structured/neater :)

It is better to use Yii::app()->clientScript->registerCssFile().

And CHtml::cssFile only generates HTML code and returns simple string and if you subsequently doing echo for two strings then you will get no line breaks.

Yeah PHP eats any linebreak right after its closing tag. If you really care about this, add an extra newline in your source:




<?php echo CHtml::cssFile('/css/reset.css', 'all'); ?>


<?php echo CHtml::cssFile('/css/style.css', 'all'); ?>




or even




<?php echo CHtml::cssFile('/css/reset.css', 'all'), "\n"; ?>

<?php echo CHtml::cssFile('/css/style.css', 'all'), "\n"; ?>



I can’t really see why it matters though.

Or you add a space after the closing tag at the end of the first line…

What difference does using registerCssFile() make?

It will add css links to page head and also separated with line breaks :).