Solved

Custom Tag Question

Posted on 2001-06-20
4
233 Views
Last Modified: 2013-12-24
Here is what I am trying to do:
 
 <cfset myArray = ArrayNew(1)>
 <cfset myArray[1] = StrucNew()>

 <cf_ctReturnSomething
      r_stOutput = "myArray[1]"
 >
 
where ctReturnSomething custom tag is defined as follows:
 
<cfset myStruct = StructNew()>
<cfset myStruct.junk = 2>
<cfset "Caller.#Attributes.r_stOutput#" = myStruct>

The problem:
The return assignment in the custom tag fails when it is desired to stuff the retun value directly into an array slot.

0
Comment
Question by:SBennett
  • 2
  • 2
4 Comments
 
LVL 4

Expert Comment

by:CF_Spike
ID: 6213604
Why don't you just add an extra line after the custom tag?

cfset myArray = ArrayNew(1)>
<cfset myArray[1] = StrucNew()>

<cf_ctReturnSomething
     r_stOutput = "stReturn"
>

<cfset myArray[1] = StructCopy(stReturn)>

I think that the problem with what you are doing is that the return variable is being seen as a string and not a variable. If you really want to get it to work you could try playing around with Evaluate().

Spike
0
 
LVL 14

Author Comment

by:SBennett
ID: 6215392
In order to get my code to work I actaully thought of and did what you suggested (which is to have the tag return a structure and insert the stucture into the array in a seperate line of code) before I ever posted this question.
   However, Just out of curiosity to see if was possible, I posted the question. So I am not looking for alternatives, I just want to know if it is possible to do what the example code a gave in my original quesion is attempting to do. (Keeping in mind that the custom tag
performs the following code:

<cfset "Caller.#Attributes.r_stOutput#" = myStruct>

It must not be aware of whether it is stuffing "myStruct" into and array or a structure or a list or whatever.)

   If someone can give me a definite "No, that's not possible" or a "Yes, it is possible and here's how you do it..." answer they will be awarded the points.

As to using the Evaluate() function:
  I have not yet had opportunity or the neccesity to get well aquainted with the evaluate(), DE(), or IIF() Funtions. I have read the cfstudio help on them and kind of undertstand the basic concepts but have not successfully used them for any thing yet. If you could show me how to use it in this situation succesfully, I will award you the points.

0
 
LVL 4

Accepted Solution

by:
CF_Spike earned 300 total points
ID: 6215743
ok,

You can't do what you want to do specifically because ColdFusion doesn't allow [] to appear in variable names and it doesn't allow you to use a complex data type as the dynamic part of a variable declaration such as:

<cfset "myvar.#someothervar#" = "junk">

If you wanted to do the same thing where the dynamic part was a structure you should be able to do that fine because you can use dot notation which is valid for variable names.

For example:

Calling page:

<CFSET myStruct = StructNew()>


<cf_ReturnSomething
     r_stOutput = "myStruct.key1"
>

<CFLOOP COLLECTION="#myStruct.Key1#" ITEM="i">
<CFOUTPUT>#myStruct.key1[i]#</CFOUTPUT>
</CFLOOP>

Custom Tag:

<cfset myStruct = StructNew()>
<cfset myStruct.junk = 2>
<cfset "Caller.#Attributes.r_stOutput#" = myStruct>

This should output the value 2.

Spike
0
 
LVL 14

Author Comment

by:SBennett
ID: 6215797
Thank you very much, cf_Spike, you have satisfied my curiosity.

-Scott
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

This is a guide to setting up a new WHM/cPanel Server to be used for web hosting accounts. It is intended for web hosting company administrators and dedicated server owners. For under $99 per month (considering normal rate of Big Data Cetnters like …
Article by: kevp75
Hey folks, 'bout time for me to come around with a little tip. Thanks to IIS 7.5 Extensions and Microsoft (well... really Windows 8, and IIS 8 I guess...), we can now prime our Application Pools, when IIS starts. Now, though it would be nice t…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now