Good deal. > So last night, I created a CFFUNCTION with just basic CF > code. This was > located in the top of my CustomTag file (embedded, not > included from an > external file). This was located at the very top of the > file, before the > <CFCASE> statements get started.
> I called the function from two locations (both in > different CFCASE > statements) and it worked like a champ! > Thanks all! >> -----Original Message----- >> From: [EMAIL PROTECTED] >> [mailto:[EMAIL PROTECTED] On > Behalf >> Of S.Isaac Dealey >> Sent: Tuesday, March 09, 2004 11:47 PM >> To: [EMAIL PROTECTED] >> Subject: RE: Recycling code in the same doc >> >> The function can be _called_ as many times as you want, >> but can only >> be _declared_ once... So in order for your tag to be >> included in the >> page more than once, the function has to be declared in a >> separate >> template that's only included once. Using <cfif> around >> the function >> declaration won't work either because the cffunction tag >> is processed >> at compile time (prior to run-time execution of any >> template) and so >> if the cffunction tag (or cfscript equivalent) exists >> anywhere in the >> template, the server will attempt to implement the >> function. You could >> put <cfif> around a cfinclude that holds the function >> declaration, but >> then again, you'd be splitting the template into 2 >> pieces. In all >> honesty I don't know why the server errors when it sees >> the 2nd >> declaration of the function (other than possibly for >> performance >> reasons -- likely the name of the class file the server >> generates is >> based on the name of the function and so if you had 2 >> separate >> functions with the same name in theory this would cause >> problems with >> their naming schema and the system wouldn't be able to >> properly >> compile the function and maintain a compiled, executable >> function >> definition. >> >> make more sense? >> >> easy enough to see this in action: >> >> <cfscript> >> function temp() { return true; } >> function temp() { return true; } >> </cfscript> >> >> Stuff that in a template and try executing it >> -- should produce an error on the 2nd function >> declaration. >> I'd be _real_ interested if it doesn't. >> >> Error generally looks something like this: >> >> Routines cannot be declared more than once. >> The routine "temp" has been declared twice in the same >> file. >> The CFML compiler was processing: >> >> a script statement beginning with "function" on line 3, >> column 3. >> a cfscript tag beginning on line 1, column 2. >> >> >> The error occurred in >> C:\Inetpub\wwwroot\dev\functions.cfm: line 3 >> >> 1 : <cfscript> >> 2 : function temp() { return true; } >> 3 : function temp() { return true; } >> 4 : </cfscript> >> 5 : >> >> Remove one of the declarations and include it twice in a >> separate >> template and you get a slightly different error, >> something like this: >> >> <cfinclude template="function.cfm"> >> <cfinclude template="function.cfm"> >> >> --- >> >> Routines cannot be declared more than once. >> The routine "temp" has been declared twice in different >> templates. >> >> ColdFusion cannot determine the line of the template that >> caused this >> error. This is often caused by an error in the exception >> handling >> subsystem. >> >> --- >> >> Christ... it's an undocumented feature ... in MX ... sort >> of ... >> >> on CF5 this >> >> <cfinclude template="function.cfm" /> >> >> produces this error (the trailing slash causes it to be >> treated as >> having an end-tag, so the tag is executed twice): >> >> Error Diagnostic Information >> >> Routines cannot be declared more than once. >> >> The routine temp has been declared twice in different >> templates. >> >> The error occurred while processing an element with a >> general >> identifier of (), occupying document position (1:1) to >> (1:1) in the >> template file C:\INETPUB\WWWROOT\DEV\FUNCTION.CFM. >> >> --- >> >> though on CFMX the same code executes fine... it also >> executes fine on >> cfmx if you use the same tag twice but without an >> end-tag, i.e. >> >> <cfmodule template="function.cfm"> >> <cfmodule template="function.cfm"> >> >> ... so ... yea, it will work with MX or with CF5 as long >> as you're not >> using end-tag syntax... I've just always avoided it >> because of the >> errors it produces in every other scenario. >> >> hth >> >> s. isaac dealey 214.823.9345 >> >> new epoch : isn't it time for a change? >> >> add features without fixtures with >> the onTap open source framework >> http://www.turnkey.to/ontap >> >> >> > I don't get it... you're saying that if you create a >> > UDF >> > within a doc, >> > and you call it multiple times, it will break? That >> > doesn't seem right, >> > since I've done that with other UDFs I've used (not my >> > own). >> >> > What am I missing? >> >> >> -----Original Message----- >> >> From: [EMAIL PROTECTED] >> >> [mailto:[EMAIL PROTECTED] On >> > Behalf >> >> Of S.Isaac Dealey >> >> Sent: Tuesday, March 09, 2004 7:30 PM >> >> To: [EMAIL PROTECTED] >> >> Subject: RE: Recycling code in the same doc >> >> >> >> yes and no... >> >> >> >> it will work if you only ever use the tag once on a >> >> given >> >> page -- >> >> otherwise it will throw an error the 2nd time the tag >> >> is >> >> called. >> >> >> >> > Right, but I'm hoping to do the "include" all within >> >> > the >> >> > same CFM >> >> > file/custom tag. (I'm trying to create a tag that is >> >> > completely >> >> > self-contained, rather than having your tag, then >> >> > callouts >> >> > to multiple >> >> > other include files. >> >> >> >> > CFFUCTION sounds like it will work for that though. >> >> >> >> >> -----Original Message----- >> >> >> >> >> You can however use includes within custom tags -- >> >> >> I've >> >> >> done it a >> >> >> number of times... I typically will put the >> >> >> includes >> >> >> for >> >> >> a given >> >> >> custom tag in a subdirectory with the same name and >> >> >> have >> >> >> the custom >> >> >> tag select between different bits to include based >> >> >> on >> >> >> its >> >> >> arguments, >> >> >> environment variables, etc. >> >> >> >> >> >> >> >> >> > You would have to write a UDF or you could even >> >> >> > wrap >> >> >> > the >> >> >> > code in a >> >> >> > <cfsavecontent> tag and use the evaluate() >> >> >> > function >> >> >> > on >> >> >> > the >> >> >> > variable >> >> >> > returned, this would cause a slight performance >> >> >> > hit >> >> >> > though. >> >> >> >> >> >> > Unfortunately, coldfusion doesn't have 'goto' >> >> >> > commands. >> >> >> >> >> >> > Take care, >> >> >> > Daniel >> >> >> >> >> >> > -----Original Message----- >> >> >> > From: [EMAIL PROTECTED] >> >> >> > [mailto:[EMAIL PROTECTED] On >> >> >> > Behalf Of Jake McKee >> >> >> > Sent: Monday, March 08, 2004 9:56 PM >> >> >> > To: [EMAIL PROTECTED] >> >> >> > Subject: Recycling code in the same doc >> >> >> > Importance: High >> >> >> >> >> >> > I'm working on a custom tag where I need to reuse >> >> >> > the >> >> >> > same >> >> >> > block of code >> >> >> > in two locations within two different <CFCASE> >> >> >> > statements. >> >> >> > I could >> >> >> > duplicate it and have it work, but of course, >> >> >> > then I >> >> >> > have >> >> >> > to keep up >> >> >> > with the same code in two locations. >> >> >> >> >> >> > Is there a way to recycle a single block of code >> >> >> > within >> >> >> > the same >> >> >> > document? Like an internal <CFINCLUDE>, so to >> >> >> > speak. >> >> >> >> >> >> > Thanks! >> >> >> > Jake >> >> >> >> >> >> > -- >> >> >> > My Blog - <http://www.smackmybooty.com> >> >> >> > www.smackmybooty.com >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> s. isaac dealey 214.823.9345 >> >> >> >> >> >> new epoch : isn't it time for a change? >> >> >> >> >> >> add features without fixtures with >> >> >> the onTap open source framework >> >> >> http://www.turnkey.to/ontap >> >> >> >> >> >> >> >> >> ----------------------------------------------- >> >> >> To post, send email to [EMAIL PROTECTED] >> >> >> To unsubscribe: >> >> >> Send UNSUBSCRIBE to [EMAIL PROTECTED] >> >> >> To subscribe / unsubscribe: http://www.dfwcfug.org >> >> >> >> >> >> >> >> > ----------------------------------------------- >> >> > To post, send email to [EMAIL PROTECTED] >> >> > To unsubscribe: >> >> > Send UNSUBSCRIBE to [EMAIL PROTECTED] >> >> > To subscribe / unsubscribe: http://www.dfwcfug.org >> >> >> >> >> >> >> >> s. isaac dealey 214.823.9345 >> >> >> >> new epoch : isn't it time for a change? >> >> >> >> add features without fixtures with >> >> the onTap open source framework >> >> http://www.turnkey.to/ontap >> >> >> >> >> >> ----------------------------------------------- >> >> To post, send email to [EMAIL PROTECTED] >> >> To unsubscribe: >> >> Send UNSUBSCRIBE to [EMAIL PROTECTED] >> >> To subscribe / unsubscribe: http://www.dfwcfug.org >> >> >> >> > ----------------------------------------------- >> > To post, send email to [EMAIL PROTECTED] >> > To unsubscribe: >> > Send UNSUBSCRIBE to [EMAIL PROTECTED] >> > To subscribe / unsubscribe: http://www.dfwcfug.org >> >> >> ----------------------------------------------- >> To post, send email to [EMAIL PROTECTED] >> To unsubscribe: >> Send UNSUBSCRIBE to [EMAIL PROTECTED] >> To subscribe / unsubscribe: http://www.dfwcfug.org > ----------------------------------------------- > To post, send email to [EMAIL PROTECTED] > To unsubscribe: > Send UNSUBSCRIBE to [EMAIL PROTECTED] > To subscribe / unsubscribe: http://www.dfwcfug.org s. isaac dealey 214.823.9345 new epoch : isn't it time for a change? add features without fixtures with the onTap open source framework http://www.turnkey.to/ontap ----------------------------------------------- To post, send email to [EMAIL PROTECTED] To unsubscribe: Send UNSUBSCRIBE to [EMAIL PROTECTED] To subscribe / unsubscribe: http://www.dfwcfug.org
