
OnRequestEnd.cfm template
As all of you are probably aware, if you want to execute some code before a template executes, you place it in the Application.cfm. However, if there is some code that you want to display at the end of a templates execution (such as footers), you can do it with a template called OnRequestEnd.cfm. As the Application.cfm must have an upper-case A in order for it to execute correctly, OnRequestEnd.cfm must have an upper-case O, R, and E to execute.
To test it, you can create three files: Application.cfm, index.cfm, and OnRequestEnd.cfm<!--- Application.cfm --->
Start!<br>
<!--- index.cfm --->
Index!<br>
<!--- OnRequestEnd.cfm --->
End!<br>
When you run it, you should see three lines of text in your browser:
Start!
Index!
End!
When you execute a template, Cold Fusion will search the directory for an Application.cfm template and if found, will execute it. If an Application.cfm template was not found, it will search up the directory tree until it finds one. If Cold Fusion finds an OnRequestEnd.cfm template in the same directory as the Application.cfm template, it will execute it once it's finished running the template the user executed. An OnRequestEnd.cfm template located in a different directory from the Application.cfm template will never be executed. Also, if an error occurred while processing your templates, the OnRequestEnd.cfm will not be executed.
For more information, see "Mapping Out an Application Framework" in Chapter 12 of the printer or online Cold Fusion documentation for "Developing Web Applications with ColdFusion".
Return to the Cold Fusion Tips-N-Tricks topic list