Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use conditional CSS In CakePHP 2.x?

Tags:

css

php

cakephp

I have to translate this code:

<!--[if IE 7]>    <link rel="stylesheet" type="text/css" href="css/ie7-style.css" />    <![endif]-->

for CakePHP. At the moment I'm using $this->Html->css('fileName') in the view file and in the default.ctp I do echo $this->fetch('css');

But what do to when i must to use a conditional css expression like above?

Thanks

like image 623
Dail Avatar asked May 25 '26 00:05

Dail


2 Answers

If you want conditionals set inside a view file (as in not in a layout), you can do:

// in your view file
$this->Html->css('file', null, array('block' => 'ie_conditional_css'));

// in layout
<?php if ($ieConditionalCss = $this->fetch('ie_conditional_css')): ?
<!--[if lt IE 8]><?php echo $ieConditionalCss ; ?><![endif]-->
<?php endif; ?>
like image 93
tigrang Avatar answered May 27 '26 14:05

tigrang


You just put the comments around your PHP, like this:

<!--[if lt IE 8]><?php echo $html->css('filename') ?><![endif]-->

like image 23
Moin Zaman Avatar answered May 27 '26 13:05

Moin Zaman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!