I am trying to define a function in a template, but sometimes the template is called twice. I tried
<cfscript>
if (not isdefined("tested")) {
string function tested(required string component) output="false" {
if (arguments.component CONTAINS "internal") return 'N/A';
....
</cfscript>
But I still get a
I don't believe you can do what you are trying to do.
When you define a function in the code, even if you surround it by IF / ELSE, the runtime compiler is still going to parse the code for the purpose of creating the Java byte code needed to run it. So your class/function is defined twice with regard to code organization. The whole idea behind a function or component is that you move it outside of your procedural or logic code into it's own library or group of functions - that way it's easy to reuse. Sorry to be the bearer of bad news :)