Often times, you'll use some of the same elements in multiple pages; for example, navigation, headers, and footer code.
Instead of copying and maintaining it from page to page, ColdFusion allows you to reference the code stored in one file in many pages. This way you can modify one file and recognize the changes throughout an entire application.
Use the CFINCLUDE tag to automatically include an existing file in the current page.
<CFINCLUDE Template="File.cfm">
| Note: | Refer to the CFML Language Reference for ColdFusion Express for CFINCLUDE syntax. |
In this example, the navigation toolbar is included (not copied) at the top of the calling page, EmpList.cfm:
<CFINCLUDE TEMPLATE="Toolbar.cfm">
Toolbar.cfm is included for processing. Toolbar.cfm resides in the same directory as Emplist.cfm.Toolbar.cfm resided in the Templates directory underneath the calling page's directory, the syntax would be:<CFINCLUDE TEMPLATE="Templates/toolbar.cfm">
During the next procedure, use CFINCLUDE on your EmpList.cfm and FormAction.cfm pages to reuse the application's navigation code.
| To reference code in a calling page: |
EmpList.cfm in HomeSite.<!--- begin application toolbar imported from toolbar.cfm--->
And ends with this:
<!--- end application toolbar --->Toolbar.cfm file in this page:<CFINCLUDE TEMPLATE="ToolBar.cfm">
EmpList.cfm in a browser.FormPage.cfm.SearchForm.cfm.You will modify this form during the next chapter's procedures to create a search form.
EmpList.cfm in a browser and navigate to SearchForm.cfm by clicking SEARCH.The toolbar should now be included.
EmpList.cfm.
Click here to see what the Emplist.cfm looks like.
Click here to see what SearchForm.cfm looks like.
Click here to see the search form's code.
In the next chapter, you will code the form so that it really does search the database.
Move on in this chapter to review development considerations.