It is one of the most used components on the Visualforce page responsible for providing content for the <apex: insert> component, i.e., defined in the VF page.
We use this method to get input from the user for the controller method that doesn't correspond to a field on a sObject field.
Attributes
The <apex: define> component has only a single attribute, i.e., name.
1. name
The name is a string-type attribute used for specifying the name of the insert component into which the content of this defined component should be read.
Syntax:
<apex:define name="header">(page) This is the header of mypage</apex:define>
Let's take an example to understand how we can use the <apex: define> component on the Visualforce page.
ApexDefineExample.vfp
<!-- create apex page to understand the <apex: define> component -->
<apex: page >
<!-- use <apex: composition> for specifying the template-->
<apex:composition template="ApexInsertExample">
<!-- use <apex: define> for adding header and body-->
<apex:define name="header">(page)Header of ApexDefineExample Start.</apex:define>
<apex:define name="body">(page)Body of ApexDefineExample Start.</apex:define>
</apex: composition>
</apex: page>
ApexInsertExample.vfp
<!-- create an apex page that acts as the template-->
<apex: page >
<!-- use outputText and insert component -->
<apex:outputText value="(template) This is before the header"/><br/>
<apex:insert name="header"/><br/>
<apex:outputText value="(template) This is between the header and body"/><br/>
<apex:insert name="body"/>
</apex: page>