Defining Visualforce page as a Template

In our previous Salesforce Developer tutorial we have learned about How to insert single visualforce in another visualforce page. Through this Visualforce training tutorial we are going to learn about how to define Visualforce page as a Template.

How to define Visualforce page as a Template ?

To define visualforce page as a template we have to use composition component in VF page. This composition component is one of the method in creating powerful modular  visualforce pages in salesforce.com.

What does the template contain ?

When the template of the visualforce page is created, it contains static content and placeholders. This static content can be overridden by implementing page and it make easy to developer’s by not remembering every sequences of include component.

How visualforce page template is useful ?

  • Not required to remember the structure and sequences of included visualforce page.
  • It has more control over the appearance of many visualforce pages.
  • Easy for maintenance.

Important points to remember.

  1. When insert component is used in template page to define named area, this named area can be overridden by implementing page  template.
  2. We use Composition component in implementing page.
  3. Composition component is used to set the name of the page.
  4. Define component is used to provide content for the named area of the template.

Creating Visualforce page as a Template.

Create new visualforce page as shown below.

Defining Visualforce page as a Template

Click on Create page apextemplate as shown below.

Defining Visualforce page as a Template

Visualforce apex code.

Defining Visualforce page as a Template

Defining Visualforce page as a Template

From above visualforce page template, it consists of header, body and footer and also horizontal lines in between these three.

Defining Visualforce page as a Template Output.

Defining Visualforce page as a Template

Visualforce page using Template.

Defining Visualforce page as a Template

Defining Visualforce page as a Template

Here we have merged the three header, body and footer of the template. Here we have used composition component to render by itself.

Output.

Defining Visualforce page as a Template

We have successfully created visualforce page as a template.