Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CakePHP - include css based on specific pages?

I want to include a specific css file that should be applied to the homepage, and 6-7 other pages throughout my site.

I know I can do this via PHP, getting the URL, finding out what page, linking the css...etc, but I was wondering if there was a slick way (or any better way) using CakePHP to include the correct css file(s).

I realize I can link the CSS file from the specific views, but - then they wouldn't be in the <head>. Is there a way to link from a view and have it show up in the head?

I hope my questions make sense, and greatly appreciate any help.

like image 353
Dave Avatar asked Mar 28 '11 20:03

Dave


1 Answers

I realize I can link the CSS file from the specific views, but - then they wouldn't be in the <head>. Is there a way to link from a view and have it show up in the head?

Yes, they would be in the head. See the HTML Helper documentation:

If key 'inline' is set to false in $options parameter, the link tags are added to the $scripts_for_layout variable which you can print inside the head tag of the document.

So, this snippet in your view...

$this->Html->css('my-css', null, array('inline' => false));

...will add the proper <link> element to your <head>.

like image 183
Sander Marechal Avatar answered Nov 17 '22 14:11

Sander Marechal