Highlighted

calling a dynamically named cookie

Explorer ,
Feb 24, 2019

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,

^ _ ^

Views

364

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

calling a dynamically named cookie

Explorer ,
Feb 24, 2019

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,

^ _ ^

Views

365

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Feb 24, 2019 0
Explorer ,
Feb 24, 2019

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 24, 2019 0
Adobe Community Professional ,
Feb 24, 2019

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>

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 24, 2019 0
LEGEND ,
Feb 25, 2019

Copy link to clipboard

Copied

I always use StructKeyExists(), never use isDefined() as I've heard of issues with it.

V/r,

^ _ ^

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 25, 2019 0
Explorer ,
Feb 26, 2019

Copy link to clipboard

Copied

that worked, thanks

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 26, 2019 0
LEGEND ,
Feb 26, 2019

Copy link to clipboard

Copied

BKBK should get credit for this, not me.  BKBK provided the suggestion, I just agreed. 

V/r,

^ _ ^

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 26, 2019 0
BKBK LATEST
Adobe Community Professional ,
Feb 26, 2019

Copy link to clipboard

Copied

Thanks for the mention, WolfShade​. I am happy it works.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 26, 2019 0
Adobe Community Professional ,
Feb 24, 2019

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>

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 24, 2019 0