1

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?

1

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>
0

Although the accepted answer works, I think adding through XML would be cleaner, as it would allow you to remove the added item through xml conditionally later:

<action method="addItem">
    <type>js</type>
    <name>html5.js</name>
    <params/>
    <if>lt IE 9</if>
</action>
<action method="removeItem">
    <type>js</type>
    <name>html5.js</name>
    <params/>
    <if>lt IE 9</if>
</action>

source: http://wabism.com/magento-ie-only-stylesheet/

However, for this to work the script has to be hosted locally, as items with <type>js</type> will have the site url prepended.

Something along the lines of what is documented on http://inchoo.net/magento/how-to-add-external-javascript-css-file-to-magento/ has to be done to enable support for external support. Note: I could not get the Inchoo this to work with conditionals in <if></if> (reported).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.