Magento 1.8 – How to Conditionally Load an External JS File in local.xml

javascriptmagento-1.8xml

I'm just getting started with Magento, and am setting up my local.xml file for the first time. I'm trying to load the html5shiv script from google code, on the condition that the browser is older than IE 9. So, I want the header file to include the following code:

<!--[if lt IE 9]>
  <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->

I've figure out how to load an external js file. My code is currently:

        <reference name="head">
        <block type="core/text" name="shim">
            <action method="setText"><text><![CDATA[<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>]]></text>  
            </action>
        </block>   
        </reference>

That works fine to load the external file. But, I'm at a loss as to how to turn this into a conditional comment. I've tried adding the following before the closing action tag:

                <params/>
                <if>IE</if> 

But that didn't do anything. Anyone know how to make this a conditional comment?

Best Answer

If you are using a core/text block include the full text you want printed inside the text tag

<reference name="head">
    <block type="core/text" name="shim">
        <action method="setText"><text><![CDATA[<!--[if lt IE 9]><script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script><![endif]-->]]></text>  
        </action>
    </block>   
</reference>