Search code examples
salesforceapex-codevisualforce

How to add a visualforce page to the end of existing page according to a condition?


Suppose we have a custom salesforce controller and a custom visualforce page for it. at the end of the visualforce page I like to evaluate a public member variable of the controller and if it is true I like to add the contents of another visualforce page (e.g. apex/test) to the first page.

<apex:page controller="mycontroller">
...........
my tags and page contents comes here
...........

{!if(my_member_variable == true, attach contents of "apex/test" page to end of this page, "do nothing")}

</apex:page>

How can I do that?

In simple words, I am searching for a command similar to include() on PHP for visualforce.

Thanks,


Solution

  • Sounds like you want to use an apex:include along with its rendered attribute.

    <apex:page controller="mycontroller">
        <!-- ... -->
        <apex:include pageName="TheNameOfTheIncludedPage" rendered="{!my_member_variable}"/>    
    </apex:page>
    

    Incidentally. The salesforce.stackExchange.com is a great place to ask Salesforce specific questions.