function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
sbrmathsbrmath 

Conditional display of link

Is it possible to display link based on certain condition on the page itself?

 

Here is what i want to to

If (condition) {

<apex:outputLink value="/{!result.account.Id}" target="_parent"> {!result.account.FirstName + ' ' + result.account.LastName} </apex:outputLink>

 

} else {

<apex:outputtext value="{!result.account.FirstName + ' ' + result.account.LastName}"/>

 

}

condition  is based on value in another variable on the page.

 

What is the exact syntax for if on the visualforce page? 

Best Answer chosen by Admin (Salesforce Developers) 
prageethprageeth

Hi sbrmath;

 

You meant something like this?

 

<apex:page>

<apex:variable value="showSecond" var="myVar" />

<apex:outputlink rendered="{!myVar=='showFirst'}" >I am FIRST link</apex:outputlink>

<br/>

<apex:outputlink rendered="{!myVar=='showSecond'}" >I am SECOND link</apex:outputlink>

<apex:page>

 


 

All Answers

ShikibuShikibu

If this is an output page, then you use this syntax.

 

 

{!IF(opportunity.IsPrivate, "Private", "Not Private")}

 

 Or, if you have a custom controller or extension, you can create a property, like this:

 

 

public String myLink { get { if (condition) { return blah; } return other_blah; } }

 

If this is an edit page, and you want to rerender the link dynamically as the user inputs something, then you'll need actionSupport and rerender.

 

 

 

 

 

prageethprageeth

Hi sbrmath;

 

You meant something like this?

 

<apex:page>

<apex:variable value="showSecond" var="myVar" />

<apex:outputlink rendered="{!myVar=='showFirst'}" >I am FIRST link</apex:outputlink>

<br/>

<apex:outputlink rendered="{!myVar=='showSecond'}" >I am SECOND link</apex:outputlink>

<apex:page>

 


 

This was selected as the best answer
sbrmathsbrmath
That works, Thanks!