Zend Framework IE conditional stylesheets and scripts
2010 March 5
You can append a conditional stylesheet in a controller action like this:
-
$this->view->headLink()->appendStylesheet('/path/to/some/styles.css', 'screen', 'IE 8');
Which would produce this markup:
<!--[if IE 8]> <link href="/path/to/some/styles.css" media="screen" rel="stylesheet" type="text/css" /><![endif]-->
Adding a conditional JavaScript file is similar:
-
$this->view->headScript()->appendFile('/path/to/some/script.js', 'text/javascript', array('conditional' => 'IE'));
And that would produce markup like this:
<!--[if IE]> <script type="text/javascript" src="/path/to/some/script.js"></script><![endif]-->
It can pretty useful when you need to use IE conditional comments just for a single controller action. Otherwise, if it applies site-wide, it’s better to just put conditional stylesheets and/or scripts in a layout file.
2 Responses
leave one →
this helps me a lot.. thanks man… keep it up
nice and informative post. I saw some more about Zend framework at http://www.anylinuxwork.com/frameworks/php-zend-development.html
looking to have some more information about Zend and its implementation from your side.