Thistag.GeneratedContent Problem

Hi

I have a problem with thistag.GeneratedContent.

Here what i want to do

Calling Template Code

<cfset Var_text = "this is a test statement">
<cf_calltag >
#Var_text#
</cf_calltag>


Here is calltag.cfm code

<CFIF thistag.ExecutionMode EQ "end">

<CFSET Test = thistag.GeneratedContent>

<cfoutput>#Test#</cfoutput>
<CFSET thistag.GeneratedContent ="">
</CFIF>

I want that output should be "this is a test statement" but it displays "#Var_text#". I have used evaluate function as well but in vain.

I am using nested tags and I want manipulation on the basis of "thistag.generatedcontent" value.

In the ColdFusion documentation they clearly written that thistag.GeneratedContent evaluate all coldfusion variables and function along with text and html. I am copying their description here.

"Custom tags can access and modify the generated content of any of its instances using the thisTag.GeneratedContent variable. In this context, the term generated content means the results of processing the body of a given tag. This includes all text and HTML code in the body, the results of evaluating ColdFusion variables, expressions, and functions, and the results generated by descendant tags. Any changes to the value of this variable results in changes to the generated content."

Does any one have any clue about this.

Thanks
BarraqAsked:
Who is Participating?
 
heathprovostConnect With a Mentor Commented:
Im sorry but what you are trying to do is basically impossible using CF custom tags... The use of the cfoutput tags is pretty much required to acheive the effect you are looking for. Either that, our you would have to write a CFX binary tag.  

The reason Now() works when you use evaluate from the custom tag is because Now() is a function and is not limited in any way by scope.  Variables, on the other hand, always have a defined scope. Most of the variables which would be used in a CFMAIL tags body would tend to be either page level or query variables (of course technically it could be pretty much anything).

The problem is that CF isolates the customtag from the most of the scopes in the calling template. Page and Query variables are not directly accesible from your customtag, it cant see these scopes directly.  If you tried to do this using evaluate, you would find that CF will give errors because the variables are undefined... Like I said before, the documentation is NOT wrong, you are just reading too much into it. evaluate() can easily process variables, but it must be able to SEE them.

On the other hand, some scopes, like application, session, request, etc. are accessible, but I think it would be more troublesome to require the coder to make sure all variables are in a certain scope than to just make them use CFOUTPUT around the body...

I know this isnt what you wanted to hear, but I really dont know any other way of doing this other than requiring the coder to place cfoutputs around the tag body...

Heath
0
 
heathprovostCommented:
You are mis-interpreting their description of this... The page in which the tag is called is what processes the body of a customtag, not the customtag itself (at lest when you do it the way you are describing).  The customtag recieves the _output_ of this processing, not the CF code which produced it. You are free to do anything you want with this output, including modifying it, but this variable will always contain the output of code, not the code itself...

The code you listed will work correctly if done like this:

Calling Template Code

<cfset Var_text = "this is a test statement">
<cf_calltag >
<cfoutput>#Var_text#</cfoutput> <!---added cfoutput here--->
</cf_calltag>


Here is calltag.cfm code

<CFIF thistag.ExecutionMode EQ "end">

<CFSET Test = thistag.GeneratedContent>

<cfoutput>#Test#</cfoutput>
<CFSET thistag.GeneratedContent ="">
</CFIF>

This of course may not be the effect you desire. Could you describe exactly what you are trying to accomplish?

Heath
0
 
BarraqAuthor Commented:
Actualy I am trying to write down a replacement of cfmail tag. We have written an EMAIL SMTP Service using IMAP4.

What i want is that a replacement of cfmail as that user only have to replace cfmail with cf_mail and rest will work as it is. Using <cfoutput> (which is not required for cfmail tag) my cf_mail works properly but I don't want to use cfoutput tag.

Regarding thistag.GeneratedContent I still think it should have to do that as if you write down any cf function like Now() without cfoutput and use
<cfoutput>Evaluate("thistag.GeneratedContent")</cfoutput> in the calling tag then it will display the system date. Problem arrives only when I use variables while in the document they clearly mentioned it that it will also evaluate the ColdFusion variables as well. As it can manipulate cf function it should have to manipulate ColdFusion variables.

Am i still wrong. Please reply if is it possible or not?

thanks

0
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
substandCommented:
you still need help on this?
0
 
BarraqAuthor Commented:
hi substand

Yes Please if you can
0
 
substandCommented:
actually, after reading all of that... i have to go with heathprovost... i think you should accept that answer.
0
 
mrichmonCommented:
No comment has been added lately, so it's time to clean up this question.
I will leave the following recommendation in the Cleanup topic area:

Accept heathprovost

Please leave any comments here within the next four days.

mrichmon
EE Cleanup Volunteer
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.