3

We would like to include a visualforce file only if the user is not running lightning Tried using this but the syntax is not right.

{!IF( $User.UIThemeDisplayed != 'Theme4d',<apex:includeScript value="{!URLFOR($Resource.myzip, '/myfile.js')}"/>)}

But get the error: Error: Syntax error. Found '<'
After saving the file. Does anybody know if this supported and what is the right syntax? Thanks in advance.

2 Answers 2

7

You can conditionally render it by using apex:outputText:

<apex:outputText rendered="{!$User.UIThemeDisplayed != 'Theme4d'}">
<apex:includeScript value="{!URLFOR($Resource.myzip, '/myfile.js')}"/>
</apex:outputText>

This will automatically include the appropriate file as necessary.

4
  • outputText instead of outputPanel is because it also works in lightning UI?
    – Raul
    Jun 30, 2017 at 5:58
  • 2
    @Rahul There's really not much difference between the two; either will get the job done. I just tend to go with the shorter code.
    – sfdcfox
    Jun 30, 2017 at 6:02
  • using outputPanel with layout="none" would include the script without generating any HTML tags for the panel itself, which might be a bit cleaner for what that's worth. developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/… Oct 15, 2018 at 14:25
  • As Raul mentioned, outputText is a good option. outputPanel adds extra <span> and having the span inside the head tags make your HTML invalid.
    – Asif
    Jul 25, 2020 at 11:30
0

Use outputPanel with render condition it will work in all scenario

<apex:outputPanel  rendered="{!$User.UIThemeDisplayed != 'Theme4d'}">

Thank you Amol Salve Salesforce Developer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .