---
schema_version: "1"
id: 48cbc939e40f22c5e995cc636e03ddc82b6efb8195aedd466d794304e70a28e8
title: Referencing an Existing Page with <apex:include>
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/platform/salesforce-pages-developers-guide/guides/pages/templates/pages-templates-include.md
canonical_url: https://developer.salesforce.com/docs/platform/salesforce-pages-developers-guide/guide/pages-templates-include.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: b79d7637ce147514780e6e7e13cd7cb6f333c1082d5bb0829ae392f3b1315bb3
products:
  - Visualforce Developer Guide
  - Platform Developer Content
---

# Referencing an Existing Page with \<apex\:include>

Use the `<apex:include>` tag when you want to duplicate the entire content of another page without making any changes. You can use this technique to reference existing markup that will be used the same way in several locations.

**note:** You should not use `<apex:include>` if you are only duplicating components. [Custom components](https://developer.salesforce.com/docs/platform/salesforce-pages-developers-guide/comp-cust/pages-comp-cust.md) are better suited for reusable segments of code.

For example, suppose you want to create a form that takes a user's name and displays it back to them. First, create a page called `formTemplate` that represents a reusable form and uses a controller called `templateExample`:

```visualforce
<apex:page controller="templateExample">
    <!-- You'll add the form markup in the next step. -->
</apex:page>
```

After you receive the prompt about `templateExample` not existing, use the following code to define that custom controller:

<!-- otherprops: apex_code set_clipboard -->

```apex
public class templateExample{

    String name;
    Boolean showGreeting = false;

    public PageReference save() {
        showGreeting = true;
        return null;
    }

    public void setNameField(String nameField) {
        name = nameField;
    }

    public String getNameField() {
        return name;
    }

    public Boolean getShowGreeting() {
        return showGreeting;
    }
}
```

Next, return to `formTemplate` and add the following markup:

<!-- otherprops: pageName=formTemplate apex_page set_clipboard -->

```visualforce
<apex:page controller="templateExample">
    <apex:form>
        <apex:outputLabel value="Enter your name: " for="nameField"/>
        <apex:inputText id="nameField" value="{!nameField}"/>
        <apex:commandButton action="{!save}" value="Save" id="saveButton"/>
    </apex:form>
</apex:page>
```

Note that nothing should happen if you click **Save**. This is expected behavior.

Next, create a page called _displayName_, which includes `formTemplate`:

<!-- otherprops: apex_page set_clipboard -->

```visualforce
<apex:page controller="templateExample">
    <apex:include pageName="formTemplate"/>
    <apex:actionSupport event="onClick"
                        action="{!save}"
                        rerender="greeting"/>
    <apex:outputText id="greeting" rendered="{!showGreeting}" value="Hello {!nameField}"/>
</apex:page>
```

When you save this page, the entire `formTemplate` page is imported. When you enter a name and click **Save** the form passes a `true` value to the `showGreeting` field, which then renders the `<apex:outputText>` and displays the user's name.

You can create another Visualforce page that uses `formTemplate` to display a different greeting. Create a page called `displayBoldName` and use the following markup:

<!-- otherprops: apex_page set_clipboard -->

```visualforce
<apex:page controller="templateExample">
    <style type="text/css">
    .boldify { font-weight: bolder; }
    </style>
    <apex:include pageName="formTemplate"/>
    <apex:actionSupport event="onClick"
                        action="{!save}"
                        rerender="greeting"/>
    <apex:outputText id="greeting" rendered="{!showGreeting}"
                     styleClass="boldify"
                     value="I hope you are well, {!nameField}."/>
</apex:page>
```

Notice that although the displayed text changes, the `templateExample` logic remains the same.
