Apex:include Component
The apex:include
component in Salesforce's Visualforce framework is used to include a Visualforce page as a component within another Visualforce page. This allows for modular development of Visualforce pages and helps in reusability of code.
Syntax
The syntax for the apex:include
component is as follows:
<apex:include pageName="[Visualforce Page Name]"/>
Example
Consider a scenario where you have a Visualforce page parentPage
that needs to include another Visualforce page childPage
. The following code shows how this can be accomplished using the apex:include
component:
<!-- parentPage -->
<apex:page>
<!-- page content -->
<apex:include pageName="childPage"/>
<!-- more page content -->
</apex:page>
<!-- childPage -->
<apex:page>
<h2>This is the child page</h2>
<p>Some content goes here</p>
</apex:page>
Explanation
In the example above, the apex:include
component is used to include the childPage
Visualforce page within the parentPage
Visualforce page. When the parent page is loaded, the child page will be automatically included, and the content of the child page will be displayed within the parent page.
Use
The apex:include
component is used to include one Visualforce page within another Visualforce page. This can help in modular development of Visualforce pages and improving code resuability.
Important Points
- The
pageName
attribute of theapex:include
component specifies the name of the Visualforce page to be included. - The included page is subject to the same Visualforce page lifecycle as the parent page.
- Visualforce pages that are included using
apex:include
cannot be triggered directly by a user.
Summary
The apex:include
component in Salesforce's Visualforce framework is used to include one Visualforce page within another. This improves code reusability and allows for modular development of Visualforce pages. The included page is subject to the same lifecycle as the parent page, and cannot be triggered directly by a user.