September 2, 2009

Reusing code with CFINCLUDE

Posted in Coldfusion at 6:19 pm by borawlings

Reusing code with CFINCLUDE

 The CFINCLUDE function is a great way to share code throughout your application.  I usually use this code to share buttons throughout forms within applications.  That way if I need to make a change to a button’s link, I only have to change the code in one place and the change is shared throughout my application wherever the buttons are needed.

 Here’s the code for BTNS_ADMIN.html. 

<input value=”Sponsored Progs”/>

<input value=”William and Mary”/>

<input value=”Places to Stay”/>

 When this code runs, three buttons are displayed.  Each button has an “onclick” attribute set to a particular location.

 Now, CFINCLUDE is used to call BTNS_ADMIN.html on the form

FRM_Show_buttons.cfm:

 <!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>

<html xmlns=”http://www.w3.org/1999/xhtml”>

<head>

<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″ />

<title>Untitled Document</title>

</head>

 <body>

<cfinclude template=”BTNS_Admin.html”>

</body>

</html>

 And that’s it!!!

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.