cfexit

Description

Used to:

Category

Flow-control tags

Syntax


<cfexit method = "method"> 

See also

cfabort, cfbreak, cfexecute, cfif    cfelseif    cfelse, cflocation, cfloop, cfswitch    cfcase    cfdefaultcase, cfthrow, cftry cfcatch

Attributes

Attribute
Description
method
Optional. Specifies one of the following:
  • exitTag (default)    Aborts processing of the currently executing CFML custom tag.
  • exitTemplate    Exits the template of the currently executing CFML custom tag.
  • loop    Reexecutes the body of the currently executing CFML custom tag.

Usage

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 executes in the same way as cfabort. The cfexit tag can help simplify error checking and validation logic in custom tags.

The behavior of the cfexit tag depends on its location and execution mode:
method
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
Continue from first child in body

Example

<!--- This read-only example shows the use of cfexit --->

<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 resumes

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 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>    



Banner.Novgorod.Ru