Copy link to clipboard
Copied
Hi,
I'm trying to create a dynamic variable and then call it dynamically and I don't know if this is possible. The easiest way to explain what I'm trying to do is to show what I want to do but obviously doesn't work.
<cfcookie name = "variable#rsSet.variable_id#" value="cookievalue">
and then later I want to call it by doing something like
<cfoutput>#cookie.#rsSet.variable_id##</cfoutput>
but obviously that doesn't work. Is there a way to call the cookie without typing the exact name of the cookie?
Thanks,
Mike
I always use StructKeyExists(), never use isDefined() as I've heard of issues with it.
V/r,
^ _ ^
Copy link to clipboard
Copied
ok so i found out how to call the variable using
<cfoutput>evaluate("cookie.#rsSet.variable#")</cfoutput<
but now my problem is that I need to check to see if it is defined so what I want to do (but obviously can't) is:
<cfif isDefined("evaluate("cookie.#rsSet.variable#"))
is there a way to check to see if the dynamically named cookie is defined?
Thanks
MIke
Copy link to clipboard
Copied
wycks wrote
<cfif isDefined("evaluate("cookie.#rsSet.variable#"))
is there a way to check to see if the dynamically named cookie is defined?
In this scenario, structkeyExists is perhaps better than isDefined. Something like
<cfif structKeyExists(cookie, rsSet.variable_id)>
</cfif>
Copy link to clipboard
Copied
I always use StructKeyExists(), never use isDefined() as I've heard of issues with it.
V/r,
^ _ ^
Copy link to clipboard
Copied
that worked, thanks
Copy link to clipboard
Copied
BKBK should get credit for this, not me. BKBK provided the suggestion, I just agreed.
V/r,
^ _ ^
Copy link to clipboard
Copied
Thanks for the mention, WolfShade. I am happy it works.
Copy link to clipboard
Copied
wycks wrote
Hi,
I'm trying to create a dynamic variable and then call it dynamically and I don't know if this is possible. The easiest way to explain what I'm trying to do is to show what I want to do but obviously doesn't work.
<cfcookie name = "variable#rsSet.variable_id#" value="cookievalue">
and then later I want to call it by doing something like
<cfoutput>#cookie.#rsSet.variable_id##</cfoutput>
Do you mean <cfcookie name = "#rsSet.variable_id#" value="cookievalue">?
If so then you could just do:
<cfoutput>#cookie[rsSet.variable_id]#</cfoutput>