Does anyone know if its possible to invoke a fuseaction within a coldfusion template?
2 Answers
(You haven't specified which Fusebox version; this answer applies to Fusebox 5.x)
Your title and question is asking two different things - a fuse and a fuseaction are two distinct things. A fuse is simply a CFML template, whilst a fuseaction represents a bundle of logic that performs a particular action (similar to a function).
Fuses:
To invoke a fuse, simply include the file as you would normally - there's no special FB functionality required for this.
Fuseactions:
To invoke a fuseaction, use the do verb, like so:
<cfset myFusebox.do('circuit.fuseaction') />
To store the result, use the second argument for the content variable:
<cfset myFusebox.do('circuit.fuseaction',varname) />
This is the equivalent of this XML:
<do action="circuit.fuseaction" contentvariable="varname" />
There are other arguments available, see this Fusebox cheat sheet which contains plenty of other useful info too.

- 110,170
- 32
- 120
- 176
-
Fuseactions is what I was looking for, and I will give your solution a try. Thanks I will let you know. – Flocknet Dec 22 '12 at 19:28
With MVC, you should be working through a single entry-point. So only a single fuseaction should be called during your request.
BUT that fuseaction can call some of the other model and view templates as needed. And I believe that Fusebox allows you to refactor that logic into something that can be used by multiple actions. (I'm a bit rusty on my Fusebox functionality though, but I bet some Googling will lead you the way.)
As a dire last resort, you could use <cfhttp>
to call a URL within your app that invokes that fuseaction. But why not just run some of the code directly without needing to burden your server with another HTTP call?

- 17,918
- 6
- 49
- 65
-
1_"So only a single fuseaction should be called during your request."_ - nope. There will be a single entry point, but it is perfectly valid (and encouraged) to divide the request up into further sub-fuseactions. There's even the ability to set prefuseaction and postfuseactions. – Peter Boughton Dec 22 '12 at 15:56
-
_"And I believe that Fusebox allows you to refactor that logic into something that can be used by multiple actions."_ I suppose the proper way to describe this was with a "prefuseaction." I think prefuseactions are a much more expressive way to run refactored controller logic, and it is in line with more modern development practices. (Think `before_filter` in Rails and `filters()` in CFWheels.) – Chris Peters Dec 22 '12 at 19:50