Harendra Singh
Harendra Singh

Reputation: 203

How can I check variable is defined or not in ColdFusion

I want a if condition in ColdFusion which is check #firstWordCategory# variable is defined or not.

Upvotes: 0

Views: 7554

Answers (2)

Abhishekh Gupta
Abhishekh Gupta

Reputation: 6236

Every variable will be in some scope and scope(mostly) is simply a structure.

So, you can use structKeyExists() like this:

<!--- If your variable is in VARIABLES scope --->
<cfif structKeyExists(VARIABLES, "firstWordCategory")>

    <!--- Your Code --->

</cfif>

Upvotes: 9

Viv
Viv

Reputation: 326

To check any variable existence you can use isDefined function:

<cfif isDefined("firstWordCategory")>
    <cfoutput>#firstWordCategory#</cfoutput>
</cfif>

For more check this.

Upvotes: 6

Related Questions