• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

calling a dynamically named cookie

Explorer ,
Feb 24, 2019 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

Views

635

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
community guidelines

correct answers 1 Correct answer

LEGEND , Feb 25, 2019 Feb 25, 2019

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

V/r,

^ _ ^

Votes

Translate

Translate
Explorer ,
Feb 24, 2019 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

Votes

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
community guidelines
Community Expert ,
Feb 24, 2019 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>

Votes

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
community guidelines
LEGEND ,
Feb 25, 2019 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,

^ _ ^

Votes

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
community guidelines
Explorer ,
Feb 26, 2019 Feb 26, 2019

Copy link to clipboard

Copied

that worked, thanks

Votes

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
community guidelines
LEGEND ,
Feb 26, 2019 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,

^ _ ^

Votes

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
community guidelines
Community Expert ,
Feb 26, 2019 Feb 26, 2019

Copy link to clipboard

Copied

LATEST

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

Votes

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
community guidelines
Community Expert ,
Feb 24, 2019 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>

Votes

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
community guidelines
Resources
Documentation