---
schema_version: "1"
id: b2037abf849d4b3608e97c913259c22af19186fb54dd6d51022fb761526cf77a
title: apex:composition
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/platform/salesforce-pages-developers-guide/guides/pages/components/pages-compref-composition.md
canonical_url: https://developer.salesforce.com/docs/platform/salesforce-pages-developers-guide/guide/pages-compref-composition.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 74eb0b7a5137188aff7f097287005af4491ce1b6dd6c7a1c8d7bfa77c7d74a5d
products:
  - Visualforce Developer Guide
  - Platform Developer Content
---

# apex:composition

An area of a page that includes content from a second template page. Template pages are Visualforce pages that include one or more `<apex:insert>` components. The `<apex:composition>` component names the associated template, and provides body for the template's `<apex:insert>` components with matching `<apex:define>` components. Any content outside of an `<apex:composition>` component is not rendered.

Use this component to get user input for a controller method that does not correspond to a field on an sObject. Only `<apex:inputField>` and `<apex:outputField>` can be used with sObject fields.

See also: `<apex:insert>`, `<apex:define>`

## Example

```apex
<!-- Page: composition -->
<!-- This page acts as the template. Create it first, then the page below.  -->	
<apex:page>
	<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>
			
<!-- Page: page -->
<apex:page>
	<apex:composition template="composition">
		<apex:define name="header">(page) This is the header of mypage</apex:define>
		<apex:define name="body">(page) This is the body of mypage</apex:define>
	</apex:composition>
</apex:page>
```

The example above renders the following HTML:

```html
(template) This is before the header<br/>
(page) This is the header of mypage<br/>
(template) This is between the header and body<br/>
(page) This is the body of mypage
```

## Attributes

|Attribute Name|Attribute Type|Description|Required?|API Version|Access|
|--------------|--------------|-----------|---------|-----------|------|
|`rendered`|String|This attribute has no effect on the display of this component. If you wish to conditionally display a `<apex:component>` wrap it inside a `<apex:outputPanel>` component, and add the conditional expression to **its** `rendered` attribute.| |10.0|global|
|`template`|ApexPages.PageReference|The template page used for this component. For this value, specify the name of the Visualforce page or use merge-field syntax to reference a page or PageReference.|Yes|10.0|global|

**See Also**  


-   [apex:define](https://developer.salesforce.com/docs/platform/salesforce-pages-developers-guide/guide/pages-compref-define.md)
-   [apex:insert](https://developer.salesforce.com/docs/platform/salesforce-pages-developers-guide/guide/pages-compref-insert.md)
-   [Defining Templates with \<apex:composition\>](https://developer.salesforce.com/docs/platform/salesforce-pages-developers-guide/templates/pages-templates-composition.md)

