Referencing CSS files

Published on and tagged with cakephp  css

Some time ago I wrote a post titled “Referencing Javascript files” in which I explained how you can reference Javascript files.

Now I noticed that the same approach also can be used for CSS files. For this purpose an additional parameter was added to the css() function in the HtmlHelper in CakePHP 1.2. So to load a page-specific CSS file you can add the following code to your view (notice the fourth parameter):

$html->css('page_specific', null, null, false);

Or if you want to load multiple CSS files:

$html->css(array('first', 'second'), null, null, false);

To make those snippets work you must have the variable $scripts_for_layout in your layout:

    <?php echo $scripts_for_layout; ?>

It is the same variable used in the approach to reference Javascript files.

3 comments baked

© daniel hofstetter. Licensed under a Creative Commons License