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
West415West415 

Conditionally display apex tags?

Hi,

 

I'm a bit new to Visualforce development, but I'm hoping someone can provide the syntax necessary to do what I want here. 

 

I have this Visualforce page and I want to conditionally display certain apex tags in the page based a value in the query string.


Here is my code.  If the value "city" is in the query string I want to show the block of code in "Code B" below otherwise show the block of code in 'Code A".  Basically one block of code is wrapped with a site template and the other is not.

 

What would the code need to look like to achive this based on a URL/Query String parameter

 

<!-- Code A -->
<apex:page controller="MyCustomController" sidebar="false" showheader="false">

  <apex:define name="body">
      
      <apex:form>
      
      </apex:form>
      
  </apex:define>

</apex:page>



<!-- Code B -->
<apex:page controller="MyCustomController" sidebar="false" showheader="false">

  <apex:composition template="{!$Site.Template}">
 
    <apex:define name="body">
        
        <apex:form>
        
        </apex:form>
        
    </apex:define>
    
  </apex:composition>

</apex:page>

 

Thanks and any help appreciated.

Best Answer chosen by Admin (Salesforce Developers) 
APathakAPathak

Hi,

You may use the rendered tag as follows.

 

<!-- Code B -->
<apex:page controller="MyCustomController" sidebar="false" showheader="false">

  <apex:composition template="{!$Site.Template}" rendered="{!isCity}">
 
    <apex:define name="body">
        
        <apex:form>
        
        </apex:form>
        
    </apex:define>
    
  </apex:composition>

</apex:page>

 The boolean variable isCity need to be defined in MyCustomController :

public class MyCustomController
{
    
    public Boolean isCity{get;set;}//Set the value of this acc to ur logic
    public MyCustomController()
    {
       
    }
}