CFEXIT can be used to:
<CFEXIT METHOD="method">
Optional. Specifies one of the following:
If a CFEXIT tag is encountered outside the context of a custom tag, for example in the base page or an included page, the tag acts exactly like CFABORT. CFEXIT can help simplify error checking and validation logic in custom tags.
CFEXIT behaves differently depending on location and execution mode:
METHOD attribute | Location of CFEXIT call | Behavior |
---|---|---|
ExitTag | Base template | Terminate processing |
Execution mode = Start | Continue after end tag | |
Execution mode = End | Continue after end tag | |
ExitTemplate | Base template | Terminate processing |
Execution mode = Start | Continue from first child in body | |
Execution mode = End | Continue after end tag | |
Loop | Base template | Error |
Execution mode = Start | Error | |
Execution mode = End |
<!--- This example shows the use of CFEXIT, and is a read-only example ---> <HTML> <HEAD> <TITLE>CFEXIT Example</TITLE> </HEAD> <BODY> <H3>CFEXIT Example</H3> <P>CFEXIT can be used to abort the processing of the currently executing CFML custom tag. Execution will resume immediately following the invocation of the custom tag in the page that called the tag. <H3>Usage of CFEXIT</H3> <P>CFEXIT is used primarily to perform a conditional stop of processing inside of a custom tag. CFEXIT returns control to the page that called that custom tag, or in the case of a tag called by another tag, to the calling tag. <!--- CFEXIT can be used inside a CFML custom tag, as follows: ---> <!--- Place this code (uncomment the appropriate sections) inside the CFUSION/customtags directory ---> <!--- MyCustomTag.cfm ---> <!--- This simple custom tag checks for the existence of myValue1 and myValue2. If they are both defined, the tag adds them and returns the result to the calling page in the variable "result". If either or both of the expected attribute variables is not present, an error message is generated, and CFEXIT returns control to the calling page. ---> <!--- <CFIF NOT IsDefined("attributes.myValue2")> <CFSET caller.result = "Value2 is not defined"> <CFEXIT METHOD="ExitTag"> <CFELSEIF NOT IsDefined("attributes.myValue1")> <CFSET caller.result = "Value1 is not defined"> <CFEXIT METHOD="ExitTag"> <CFELSE> <CFSET value1 = attributes.myValue1> <CFSET value2 = attributes.myValue2> <CFSET caller.result = value1 + value2> </CFIF> ---> <!--- End MyCustomTag.cfm ---> <!--- And place this code inside your page ---> <!--- <P>The call to the custom tag, and then the result: <CF_myCustomTag myvalue2 = 4> <CFOUTPUT>#result#</cFOUTPUT> ---> <P>If CFEXIT is used outside of a custom tag, it functions like a CFABORT. For example, the text after this message will not be processed: <CFEXIT> <P>This text will not be executed due to the existence of the CFEXIT tag above it. </BODY> </HTML>