Newer Version Available
Defining Templates with <apex:composition>
All templates defined using <apex:composition> must have one or more child <apex:insert> tags. An <apex:insert> tag indicates to pages that import the template that a section needs a definition. Any Visualforce page that imports a template using <apex:composition> must use <apex:define> to specify the content of each <apex:insert> section of the template.
You can create a skeleton template that allows subsequent Visualforce pages to implement different content within the same standard structure. To do so, create a template page with the <apex:composition> tag.
The following example shows how you can use <apex:composition>, <apex:insert>, and <apex:define> to implement a skeleton template.
- When you save myFullForm, the previously defined <apex:inputText> tags and Save button appear.
- Since the composition page requires age and meal fields, myFullForm defines them as text input fields. The order in which they appear on the page does not matter; myFormComposition specifies that the age field is always displayed before the meal field.
- The name field is still imported, even without a matching <apex:define> field.
- The color field is disregarded, even though controller code exists for the field. This is because the composition template does not require any field named color.
- The age and meal fields do not need to be text inputs. The components within an <apex:define> tag can be any valid Visualforce tag.
Dynamic Templates
A dynamic template allows you to assign a template through a PageReference. The template name is assigned to a controller method that returns a PageReference containing the template you want to use.