Using Custom Components in a Visualforce Page

The body of an <apex:component> tag is the markup that is added to a standard Visualforce page whenever the component is included. For example, the following Visualforce page uses the component defined in Custom Component Markup (in this example, the component was saved with the name myComponent):

<apex:page standardController="Account">
   This is my <i>page</i>. <br/>
   <c:myComponent/>
</apex:page>

It results in the following output:

This is my page.
This is my custom component.

To use a custom component in a Visualforce page you must prefix the component's name with the namespace in which the component was defined. For example, if a component named myComponent is defined in a namespace called myNS, the component can be referenced in a Visualforce page as <myNS:myComponent>.

For ease of use, a component that is defined in the same namespace as an associated page can also use the c namespace prefix. Consequently, if the page and component from the sample above are defined in the same namespace, you can reference the component as <c:myComponent>.

If you want to insert content into a custom component, use the <apex:componentBody> tag.

Previous
Next