• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL

Chapter 4. Handling a Fuseaction > Section 10: Target fbx_switch.cfm

Section 10: Target fbx_switch.cfm

This section includes the target circuit’s fbx_switch.cfm file. The fbx_switch.cfm file decides which fuses to run based on the value of fusebox.fuseaction. Here is the fbx_switch.cfm file from the reviews circuit:

<cfswitch expression = "#fusebox.fuseaction#"> 
  <cfcase value="read"> 
    <cfset xfa.addReview="#fusebox.thisCircuit#.reviewForm"> 
    <cfinclude template="qry_reviewByProduct.cfm"> 
    <cfinclude template="dsp_reviews.cfm"> 
  <cfcase value="reviewForm"> 
    <cfset xfa.submit="#fusebox.thisCircuit#.addReview"> 
    <cfinclude template="dsp_reviewForm.cfm"> 
  <cfcase value="addReview"> 
    <cfset xfa.continue="#fusebox.thisCircuit#.read"> 
    <cfinclude template="qry_addReview.cfm"> 

No more code was left out. The fbx_switch.cfm consists only of a switch/case statement, switching on fusebox.fuseaction, which was set previously in the core file, based on the second half of the compound fuseaction.

Our request looks like this:

<a href="index.cfm?fuseaction=reviews.read&productID=1392"> 

The value of fusebox.fuseaction is “read,” which means that the first <cfcase> block will be run, setting an exit fuseaction. (You will learn more about exit fuseactions in Chapter 6, “Exit Fuseactions.”)

Section 10 Code

After those files are included and processed, this section is done. Here is the code for section 10:

fusebox.IsTargetCircuit= TRUE; 
if (Len(FB_.fuseboxpath)){
  FB_.fuseboxpath=FB_.fuseboxpath & "/"; 
  fusebox.IsHomeCircuit = FALSE;} 
  fusebox.IsHomeCircuit = TRUE; 
fusebox.rootPath=repeatString("../", ListLen(fb_.fuseboxpath, '/')); 
  <cfsavecontent variable="fusebox.layout"> 
    <cfoutput><cfinclude template=”#FB_.fuseboxpath#fbx_Switch.cfm”></cfoutput> 
    <cfif fusebox.suppressErrors> 
      <cfoutput>I could not find #FB_.fuseboxpath#fbx_Switch.cfm...</cfoutput><cfabort> 


The top CFScript portion of this section sets Fusebox API variables that are already familiar. Because the target circuit is the only circuit in which the fbx_switch.cfm is run, fusebox.thisCircuit is set to fusebox.targetCircuit. The core determines if this is the home circuit and sets fusebox.isHomeCircuit appropriately. Finally, fusebox.currentPath and fusebox.rootPath are updated so that they can be used in fuses for this fuseaction.

The next lines include the target fbx_switch.cfm, which processes all the fuses for the fuseaction. Just like that, all your code is processed for this fuseaction. What about that <cfsavecontent> tag?


<cfsavecontent> traps all output that occurs between its opening and closing tags in the variable specified in the name attribute. Here is a short example of its use:

<cfsavecontent name="foo"> 
  Help! I’m trapped! 
This is the content:<br> 

Even though the text Help! I’m trapped! appears before the rest of the output on the page, it is not displayed until the variable foo is referenced. When run, this page looks like this:

This is the content: 
Help! I’m trapped! 

This tag is new to ColdFusion 5, but earlier versions of ColdFusion can gain the same functionality via the custom tag <cf_savecontent>, which is what the core file for those versions uses.

Because the fbx_switch.cfm is included inside <cfsavecontent>, any output that the fuseaction generates will not be displayed. Instead, it will be trapped in the variable fusebox.layout. This means that although the combination of the fuses qry_reviewByProduct.cfm and dsp_reviews.cfm will produce a well-formatted page showing all the reviews of a particular product, nothing will show up on the page yet.

We are going to maintain the secret of where the output is actually presented for a little longer. Just remember that the output of the fuseaction is stored in fusebox.layout; we’ll come back to it soon.

  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint