November 9, 2012

How to Include One Visualforce Page within Another

Sample Code:

<apex:page>
    <p>Test Before</p>
    <apex:include pageName="MainPage"/>
    <p>Test After</p>
</apex:page>


here MainPage is a another Visualforce page.

<apex:page >
Main Page : Welcome to Infallible Techie Site
</apex:page>

Output:



8 comments:

  1. What happens if MainPage is attached to a specific controller e.g,
    <apex:page standardController="Account>.

    How do you pass the correct Account Id to the MainPage if the Primary Page is a stand alone page?

    ReplyDelete
    Replies
    1. Add extensions="Class_Name" for populating account id.

      http://www.infallibletechie.com/2013/10/how-to-get-record-id-from-standard.html

      Cheers!

      Delete
    2. Where would you add the extension?
      In the main page, or the primary page?

      Delete
  2. How to pass parameters in apex:include

    ReplyDelete
    Replies
    1. It doesn't support any attributes to send values.
      https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_compref_include.htm
      You can try to pass values in the URL and get it from the controller. Give a try.

      Delete