+ Start a Discussion
Greg LovelidgeGreg Lovelidge 

Conditional Comments in Visualforce

I've got a couple different stylesheets to deliver to different versions of internet explorer but this is proving difficult with Visualforce.  I'm sure it's possible with some creative solution, I just can't seem to find one.

 

Ideally, I would use conditional comments as I would in any html page:

 

<!--[if lte IE 8]>
<apex:stylesheet value="{!URLFOR($Resource.assets, '/assets/css/lteie8.css')}"/>
<![endif]-->

<!--[if IE 6]>
<apex:stylesheet value="{!URLFOR($Resource.assets, '/assets/css/ie6.css')}"/>
<![endif]-->

 and the VF page would generate the urls for me despite the comments and it would ouput something like this:

 

<!--[if lte IE 8]>
<link href="/resource/1295990700000/assets/assets/css/lseie8.css" rel="stylesheet" type="text/css" />
<![endif]-->

<!--[if IE 6]>
<link href="/resource/1295990700000/assets/assets/css/ie6.css" rel="stylesheet" type="text/css" />
<![endif]-->

 

Any ideas how I can output the correct code?  I figure Salesforce would have thought about this if they're serious about Sites.  It's a very common practice.

 

Thanks in advance,

 

Greg

 

sebcossebcos

Hi,

to develop cross-platform compatible pages please refer to this page from the Visualforce developer guide:

http://www.salesforce.com/us/developer/docs/pages/index_Left.htm#StartTopic=Content/pages_mobile_cross_platform.htm?SearchType=Stem

 

etoeto

I found a proper workaround:

 

Add the following two methods to your controller or to an extensions:

 

public String getLt(){
	return '<';
}	
public String getGt(){
	return '>';
}	

 Then use outputText to output the comments like this

 

<apex:outputText escape="false" value="{!lt}!--[if lt IE 10]{!gt}"/>
<script type="text/javascript" src="{!URLFOR($Resource.XXXX, 'yourfile.js')}"></script>
<apex:outputText escape="false" value="{!lt}![endif]--{!gt}"/>

 

hth

Ingo