Solved

Custom Tag Question

Posted on 2001-06-20
4
273 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Is Your DevOps Pipeline Leaking?

Is your CI/CD pipeline a hodge-podge of randomly connected tools? You’ve likely got a tool to fix one problem & then a different tool to fix another, resulting in a cluster of tools with overlapping functionality. Learn how to optimize your pipeline with Gartner's recommendations

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Are date-time stamps in Microsoft IIS log files in GMT +0? 3 66
Autoresponder for Whole Domain in Plesk/Cpanel 2 101
DNS @ Naked Domain Record 5 130
WebSite Direction 1 79
A web service (http://en.wikipedia.org/wiki/Web_service) is a software related technology that facilitates machine-to-machine interaction over a network. This article helps beginners in creating and consuming a web service using the ColdFusion Ma…
Periodically we have to update or add SSL certificates for customers. Depending upon your hosting plan you may be responsible for the installation and/or key generation. In the wake of Heartbleed many sites were forced to re-key. We will concen…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

734 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