How to Use a Template with Another Visualforce Page

Step 1. Create a new Visualforce page called BasicTemplate.

<apex:stylesheet value=""/>
<h1>My Fancy Site</h1>
<apex:insert name="body"/>

The key here is the <apex:insert> component. You won’t visit this page (unless developing it) directly. Rather, create another Visualforce page that embeds this template, inserting different values for each of the <apex:insert> components.
Note that each such component is named. In the above template, you have a single insert position named body. You can have dozens of such positions.
Step 2: Use a Template with Another Page
You can now embed the template in a new page, filling in the blanks as you go.
Create a new Visualforce page called MainPage.
Within the page, add the following markup:

<apex:page sidebar="false" showHeader="false">
<apex:composition template="BasicTemplate">
<apex:define name="body">
<p>This is a simple page demonstrating that this
text is substituted, and that a banner is created.</p>

The <apex:composition> component fetches the Visualforce template page you created earlier, and the <apex:define> component fills the named holes in that template. You can create multiple pages that use the same component, and just vary the placeholder text.

No comments:

Post a Comment

Sharing is Caring!!! Share this with your friends!!!

submit to reddit