September 2, 2009
Reusing code with CFINCLUDE
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!!!