3

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

2 Answers 2

3

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; ?>
Sign up to request clarification or add additional context in comments.

Comments

3

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

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

2 Comments

hmm are you sure? because the problem should be if i use $this->Html->css('file') inside a view. The default.ctp will prints all the css files doing $this->fetch('css') but if i do something like that i must to put it in the layout..... no?
Yes, you need to put this into the <head> of your layout any maybe add the 'inline'=>true option to make it an extra link.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.