timsayshey
timsayshey

Reputation: 221

Using a Custom Tag Variable from Outside of a Custom Tag

Ok, I thought this would be simple but I'm getting an error telling me the variable does not exist.

Here is my custom tag code:

<cfset isBot = false>
<cfif find("bot", CGI.HTTP_USER_AGENT)>
<cfset isBot = true>               
</cfif> 

Here is my page calling the custom tag:

<cf_checkBot>
<cfif isBot> 
Yes This Is A Bot!
</cfif>

So how do I use a variable outside of a customtag that was set inside of a custom tag?

Thanks :)

Upvotes: 0

Views: 242

Answers (2)

Jordan Reiter
Jordan Reiter

Reputation: 21002

You want the Caller scope:

<cfset isBot = false>
<cfif find("bot", CGI.HTTP_USER_AGENT)>
<cfset Caller.isBot = true>               
</cfif> 

Upvotes: 4

Sam Farmer
Sam Farmer

Reputation: 4118

<cfset isBot = false>
<cfif find("bot", CGI.HTTP_USER_AGENT)>
<cfset **caller.**isBot = true>               
</cfif> 

You use the caller scope.

It might be better to use a function instead of a custom tag though.

Upvotes: 3

Related Questions