Referencing an Existing Page with <apex:include>
Use the <apex:include> tag when you want to duplicate the entire content of another page
without making any changes. You can use this technique to reference
existing markup that will be used the same way in several locations.
For example, suppose you want to create a form that takes a user's
name and displays it back to them. First, create a page called formTemplate that represents a reusable
form and uses a controller called templateExample:
After you receive the prompt about templateExample not existing, use the following code to
define that custom controller:
Next, return to formTemplate and add the following markup:
Note that nothing should happen if you
click Save. This is expected behavior.
Next, create a page called displayName, which
includes formTemplate:
When you save this page, the entire formTemplate page is imported. When you enter a name and click Save the form passes a true value to the showGreeting field, which then renders the <apex:outputText> and displays the user's name.
You can create another Visualforce page that uses formTemplate to display a different greeting. Create a page called displayBoldName and use the following
markup:
Notice that although the displayed text
changes, the templateExample logic remains the same.