Skip to content

Zend Framework IE conditional stylesheets and scripts

2010 March 5

You can append a conditional stylesheet in a controller action like this:

  1. $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:

  1. $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 →
  1. Johan permalink
    March 25, 2010

    this helps me a lot.. thanks man… keep it up

  2. April 20, 2010

    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.

Leave a Reply

Note: You can use basic XHTML in your comments. Your email address will never be published.

Subscribe to this comment feed via RSS