Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with using CFOUTPUT within CFOUTPUT, or grouping, etc.! 2

Status
Not open for further replies.

rmz8

Programmer
Aug 24, 2000
210
US
I have the following code:

<CFOUTPUT QUERY=&quot;Design&quot;><body bgcolor=&quot;#Body_Attribute1#&quot; link=&quot;#Body_Attribute2#&quot; alink=&quot;#Body_Attribute3# vlink=&quot;#Body_Attribute4#&quot;>
<font face=&quot;#Font#&quot;>#Header#
#SearchResults_Body#
#Footer#
</font></body></CFOUTPUT>

The Field 'SearchResults_Body' contains the following code:

<CFOUTPUT QUERY=&quot;SearchResults&quot;><p><font size=&quot;2&quot;>• <a href=&quot;display_article.cfm?ID=#ID#&Client_Name=myjobcoach&quot;>#Headline#</a></font></p></CFOUTPUT><br><br>

When I run the page, it simply displays the code above as if I left out the CFOUTPUT tags. How can I make it so that it will work?
 
Hi!

There is two ways to do this...
1- Go on Allaire page and try to find CFX_Evaluate. I think it does exactly that... I am not sure thought.

2- Second solution but the best one and I seen it a lot, write that #SearchResults_body# field in a file using CFFILE and immediatly include the newly created file. Everything should be working fine... The only problem is performance, you will do a disk access on each loop...

Try this...
Trying to help!
 
I tried CF_Evaluate--the tag just doesn't work. The same exact problems continue to plague me. Using CFFILE/CFINCLUDE won't work because the field with be changing, etc. Style sheets have nothing to do with what I need to do.
 
Hi what do you mean the field will be changing?

I'll code it for you here:
<CFOUTPUT QUERY=&quot;Design&quot;>
<body bgcolor=&quot;#Body_Attribute1#&quot; link=&quot;#Body_Attribute2#&quot; alink=&quot;#Body_Attribute3# vlink=&quot;#Body_Attribute4#&quot;>
<font face=&quot;#Font#&quot;>#Header#
<CFFILE ACTION=&quot;WRITE&quot; FILE=&quot;C:\yourCurrentPathHere\test.cfm&quot; OUTPUT=&quot;#SearchResults_Body#&quot;>
<CFINCLUDE TEMPLATE=&quot;test.cfm&quot;>
<CFFILE ACTION ACTION=&quot;DELETE&quot; FILE=&quot;C:\yourCurrentPathHere\test.cfm&quot;>
#Footer#
</font>
</body>
</CFOUTPUT>

This will work if I understand what you want to do...

Chris
 
That's an excellent solution, but it seems to me that it's possible two templates running concurrently could write to the test.cfm file, causing one of the templates to include the wrong file... If you did this:
[tt]
.......
<CFSET ANumber=RandRange(1-9999)>
<CFFILE ACTION=&quot;WRITE&quot; FILE=&quot;C:\yourCurrentPathHere\test#ANumber#.cfm&quot; OUTPUT=&quot;#SearchResults_Body#&quot;>
<CFINCLUDE TEMPLATE=&quot;test.cfm&quot;>
<CFFILE ACTION ACTION=&quot;DELETE&quot; FILE=&quot;C:\yourCurrentPathHere\test#ANumber#.cfm&quot;>
.....
[/tt]
The odds of this happening would be reduced to about zero...
(Just my two cents on that.. :)

----------------------------------------------------------

rmz8,

I'm actually surprised it shows the code like that... I would expect CF to throw an error for trying to nest two CFOUTPUTs looping over different queries...

I would use onirike's CFINCLUDE suggestion (maybe with my modification), and end the CFOUTPUT before the CFINCLUDE statement. You can re-do the CFOUTPUT after the CFINCLUDE. Your CF won't be perfectly nested with the HTML, but you won't run into nesting problems with the CFOUTPUTs...

Hope this helps...
 
Hi!

Hum for the CFOUTPUT I didnt mention it cause it was an evidence... But it's true that he will need to modify his code to take care of it...

I did an error without thinking about concurrent access to that file...

but your code is wrong too darkman...
Here is a copy of your fixed code:
.......
<CFSET ANumber=RandRange(1-9999)>
<CFFILE ACTION=&quot;WRITE&quot; FILE=&quot;C:\yourCurrentPathHere\test#ANumber#.cfm&quot; OUTPUT=&quot;#SearchResults_Body#&quot;>
<CFINCLUDE TEMPLATE=&quot;test#ANumber#.cfm&quot;>
<CFFILE ACTION ACTION=&quot;DELETE&quot; FILE=&quot;C:\yourCurrentPathHere\test#ANumber#.cfm&quot;>
.....

hum and this could lead to a problem too if for a strange reason the random return the same value twice at the same time...

I thought using <CFLOCK>. I've never used <CFLOCK> could it be use to limit the concurrent action on that code area to 1 at the time?

I know this tag is made to use with custom tags but is it possible to use it in that case?

Trying to find the perfect solution!
Chris
 
Chris,

WHOOPS! Good catch!..:)

I think CFLOCK could be used, but that wouldn't stop the second process from writing to the file between the first's CFFILE WRITE and CFLOCK. However, the chances of two templates running concurently AND having the same random number is incredibly small (about 2 in 10,000x10,000, or 1:50,000,000, and that's for templates started at close enough to the same time that the CFFILES happen to collide)... If you want to put the risk to absolutely nothing, the code could be written like:
[tt]
.......
<CFSET ANumber=CreateUUID()>
<CFFILE ACTION=&quot;WRITE&quot; FILE=&quot;C:\yourCurrentPathHere\#ANumber#.cfm&quot; OUTPUT=&quot;#SearchResults_Body#&quot;>
<CFINCLUDE TEMPLATE=&quot;#ANumber#.cfm&quot;>
<CFFILE ACTION ACTION=&quot;DELETE&quot; FILE=&quot;C:\yourCurrentPathHere\#ANumber#.cfm&quot;>
.....
[/tt]
This will create a file name with a 128 bit Universally Unique Identifier that's pretty much guaranteed to be a unique number. (You could do a union on a million tables with a million records each on a UUID column and you wouldn't get any duplicate rows..)

Or, you could just make the spread in the RandRange larger...:)

DM
 
Well I think we got your solution here rmz8!

Thx for your input Darkman...

Chris
 
Guys, thanks so much for the solution. A question however. Does this function dynamically write to a file based on the contents of 'SearchResults_Body' (which varies depending on what record the variable calls.)?

Ryan ;-}
 
Hi Ryan!

Sure if the content 'SearchResults_Body' change, the file content and so the included code will change too...

Chris...
 
Thanks for all the help. When running the template:


It says there is an error with the syntax in the file that is being included using the CFINCLUDE tag. The text for the OUTPUT function of the CFFILE tag used to write the text file is error free. Here is the code:

<CFOUTPUT QUERY=&quot;Search&quot;><p><font size=&quot;2&quot;>• <a href=&quot;display_article.cfm?ID=#ID#&Client_Name=myjobcoach&quot;>#Headline#</a></font></p></CFOUTPUT><br><br>
 
Sorry guys! My mistake--the error was in reference to the bullet.
 
I am finding that using the solution you guys created, the temp files are not being deleted. The code you provided for the DELETE action was:

[tt]<CFFILE ACTION ACTION=&quot;DELETE&quot; FILE=&quot;C:\yourCurrentPathHere\#ANumber#.cfm&quot;>[/tt]

I figured that this was clearly a mistake (since CF returned an error), so I changed it to (removed the extra [tt]ACTION[/tt]):

[tt]<CFFILE ACTION=&quot;DELETE&quot; FILE=&quot;C:\yourCurrentPathHere\#ANumber#.cfm&quot;>[/tt]

It still doesn't work.
 
Hey Guys,

Using the code below, everything works except the delete function for some reason:

<CFSET ANumber=CreateUUID()>
<CFFILE ACTION=&quot;WRITE&quot; FILE=&quot;d:/html/users/petergoodman/myjobcoachcom/html/#ANumber#.cfm&quot; OUTPUT=&quot;#Index_Body#&quot;>
<CFINCLUDE TEMPLATE=&quot;#ANumber#.cfm&quot;>
<CFFILE ACTION=&quot;DELETE&quot; FILE=&quot;d:/html/users/petergoodman/myjobcoachcom/html/#ANumber#.cfm&quot;>


That code is taken from this page (look at the error):


I am positive that the file is being created (because I checked the directory). They just aren't being deleted!
 
The file being accessed on the site will be hit thousands upon thousands of times each day. Writing and deleting a file each time a person accesses it is not efficient at all and takes a huge toll on my bandwidth.

I desperately need another solution. Someone suggested CF_Evaluate, but the tag didn't seen to solve anything.

Please help, ASAP, it is greatly appreciated. [sig]<p>Ryan ;-]<br>[/sig]
 
Hum...
Dont have anymore idea Ryan...

And I dont know any other way to do what you want to do...

The next step would be to try to understand why you want to store some CF code in your db and to find a way to avoid this...

Please explain me what you are trying to do by doing this...
I dont think we can find a solution to this problem, now what I am trying to do is eliminate the problem by using a different way...

Waiting for your input...

Chris [sig][/sig]
 
Hey Chris,

Thanks for the prompts reply. How the system works is this:

There is an online management system where a user can logon and change different elements of a page. Based on the Client_Name value appended to every URL in the site, the customized settings will be called from the database. For example, client XYZ has data stored in the 'Header' and 'Footer' fields of the database in their own record. If I were to call the URL the Header and Footer contents entered in the database would be used to create the page.

My problem lies that within one of the fields, let's say 'Header,' contains CFML and thus uses the CFOUTPUT tag to display the pertinent information. However, when the page is loaded, the CFML appears as if there weren't any CFOUTPUT tags around it. Take the following text, for example:

<CFOUTPUT>
#Search.Summary#
</CFOUTPUT>


When the page is loaded, it would show the text:

#Search.Summary#

So, my problem is essentially that the page does not parse the code within field 'Header' as CFML. [sig]<p>Ryan ;-]<br>[/sig]
 
Hey Chris,

Thanks for the prompts reply. How the system works is this:

There is an online management system where a user can logon and change different elements of a page. Based on the Client_Name value appended to every URL in the site, the customized settings will be called from the database. For example, client XYZ has data stored in the 'Header' and 'Footer' fields of the database in their own record. If I were to call the URL the Header and Footer contents entered in the database would be used to create the page.

My problem lies that within one of the fields, let's say 'Header,' contains CFML and thus uses the CFOUTPUT tag to display the pertinent information. However, when the page is loaded, the CFML appears as if there weren't any CFOUTPUT tags around it. Take the following text, for example:

<CFOUTPUT>
#Search.Summary#
</CFOUTPUT>


When the page is loaded, it would show the text:

#Search.Summary#

So, my problem is essentially that the page does not parse the code within field 'Header' as CFML. [sig]<p>Ryan ;-]<br>[/sig]
 
Hey Ryan!

Hum... like I told you and that's what I still think is that you should try to avoid storing the code in your db...

You should create a table that would contain the information to rebuild that code.

I mean there must be a way to store all the info regarding your header with specific parameters in your DB... and then you be able depending of the user to reconstruct dynamically using those info the CF code...

I dont know if you understand...
I mean something like you could replace something like:
<CFOUTPUT QUERY=&quot;SearchResults&quot;> by a field in a db that would say to create a CFOUTOUT QUERY with SearchResults.

Because if you still stick to your first solution I think you will be still here next year asking for help! hahaha

Good luck dude...

Chris [sig][/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top