Solved

Custom Tag Question

Posted on 2001-06-20
4
252 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:Scott Bennett
  • 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:Scott Bennett
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:Scott Bennett
ID: 6215797
Thank you very much, cf_Spike, you have satisfied my curiosity.

-Scott
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In our day to day coding, how many times have we come across a necessity to check whether a URL is a broken link or not? For those of you that answered countless and are using ColdFusion like myself, then this article is for you.  It will show yo…
When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

816 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

11 Experts available now in Live!

Get 1:1 Help Now