Solved

How does one output coldfusion code that has been retrieved from database?

Posted on 2010-08-12
12
454 Views
Last Modified: 2013-12-16
Fairly simple question.  Lets say I have a hunk of code stored in a table.  I get said code chunk via a cfc, returning a query string to the page.  I access the chunk like so: <cfoutput>#queryName.codeChunk#</cfoutput>.  The code is output as it should be, but the coldfusion variables are not rendered.  What must I do to output the code WITH rendered codlfusion variables (that lie within the code chunk)?

In the end code such as this:

     templateBG = new Image();
     templateBG.src = "http://#cgi.http_host#/userfiles/#application.clientId#/templates/#this.template#/template_#this.template#_01.png";

and this:

     <img src="http://#cgi.http_host#/userfiles/#application.clientId#/templates/#this.template#/template_#this.template#_01.png">

...should be rendered with rendered variables.
0
Comment
Question by:brianmfalls
  • 6
  • 4
  • 2
12 Comments
 
LVL 52

Expert Comment

by:_agx_
Comment Utility
Try using the evaluate() function. It should force an evaluation of the CF variables within the string.
0
 
LVL 1

Author Comment

by:brianmfalls
Comment Utility
Tried that already...  :(

 Invalid CFML construct found on line 1 at column 1.
ColdFusion was looking at the following text: <

It doesn't make it past the first character (since it's a tag).  If it were plain text with variables, that would work.
0
 
LVL 52

Expert Comment

by:_agx_
Comment Utility
Can you give a _small_ example of exactly what #queryName.codeChunk# looks like?
0
 
LVL 1

Author Comment

by:brianmfalls
Comment Utility
aqx:  The original posts has two snippets from the output. of #queryName.codeChunk#.  However, If it helps, I have attached a full example.  Please let me know if I may provide any further input.  Thank you for your help.
<script type="text/javascript">	
	$(document).ready(function(){
		///////	preload templateBG ///////
		templateBG = new Image();
		templateBG.src = "http://#cgi.http_host#/userfiles/#application.clientId#/templates/#this.template#/template_#this.template#_01.png";
		templateBG = new Image();
		templateBG.src = "http://#cgi.http_host#/userfiles/#application.clientId#/templates/#this.template#/template_#this.template#_02.png";
		templateBG = new Image();
		templateBG.src = "http://#cgi.http_host#/userfiles/#application.clientId#/templates/#this.template#/template_#this.template#_03.png";
		templateBG = new Image();
		templateBG.src = "http://#cgi.http_host#/userfiles/#application.clientId#/templates/#this.template#/template_#this.template#_04.png";
		templateBG = new Image();
		templateBG.src = "http://#cgi.http_host#/userfiles/#application.clientId#/templates/#this.template#/template_#this.template#_05.png";
		templateBG = new Image();
		templateBG.src = "http://#cgi.http_host#/userfiles/#application.clientId#/templates/#this.template#/template_#this.template#_06.png";
		templateBG = new Image();
		templateBG.src = "http://#cgi.http_host#/userfiles/#application.clientId#/templates/#this.template#/template_#this.template#_07.png";
		templateBG = new Image();
		templateBG.src = "http://#cgi.http_host#/userfiles/#application.clientId#/templates/#this.template#/template_#this.template#_08.png";
		templateBG = new Image();
		templateBG.src = "http://#cgi.http_host#/userfiles/#application.clientId#/templates/#this.template#/template_#this.template#_09.png";
		templateBG = new Image();
		templateBG.src = "http://#cgi.http_host#/userfiles/#application.clientId#/templates/#this.template#/template_#this.template#_10.png";
		templateBG = new Image();
		templateBG.src = "http://#cgi.http_host#/userfiles/#application.clientId#/templates/#this.template#/template_#this.template#_11.png";
	});
</script>

<style type="text/css">
	.foot, .head {
		text-align:	center;
		width:		715px;
		margin:		14px 0px;
		padding:		0px;
	}
	table, tr, td {
		padding:	0px;
		margin:	0px;
	}
</style>

<!--- template header --->
<div class="head">
	<p>To view this email as a web page, click <a href="%%view_email_url%%">here</a>.</p>
	<p>Please add merchant@marketing.merchant.com</p>
	<p>to your Address Book or Safe Sender list to ensure delivery to your inbox.</p>
</div>

	<table cellspacing="0">
		<tr>
			<td style=" width: 723px; height: 141px; " colspan="5">
				<img src="http://#cgi.http_host#/userfiles/#application.clientId#/templates/#this.template#/template_#this.template#_01.png" width="723" height="141">
			</td>
		</tr>
		<tr>
			<td style=" width: 37px; height: 645px; " rowspan="3">	
				<img src="http://#cgi.http_host#/userfiles/#application.clientId#/templates/#this.template#/template_#this.template#_02.png" width="37" height="645">
			</td>
			<td style=" width: 650px; height: 400px; " colspan="3" class="drop650x400 areaClues" title="#request.primaryClue#" id="area3038_form">
				<img src="http://#cgi.http_host#/userfiles/#application.clientId#/templates/#this.template#/template_#this.template#_03.png" width="650" height="400">
			</td>
			<td style=" width: 36px; height: 645px; " rowspan="3">
				<img src="http://#cgi.http_host#/userfiles/#application.clientId#/templates/#this.template#/template_#this.template#_04.png" width="36" height="645">
			</td>
		</tr>
		<tr>
			<td style=" width: 650px; height: 20px; " colspan="3">			
				<img src="http://#cgi.http_host#/userfiles/#application.clientId#/templates/#this.template#/template_#this.template#_05.png" width="650" height="20">
			</td>
		</tr>
		<tr>
			<td style=" width: 315px; height: 225px; background-image: url(/userfiles/#application.clientId#/templates/#this.template#/template_#this.template#_06.png); " class="drop315x225 areaClues" title="#request.secondaryClue#" id="area3039_form">
				<img src="http://#cgi.http_host#/userfiles/#application.clientId#/templates/#this.template#/template_#this.template#_06.png" width="315" height="225">
			</td>
			<td style=" width: 20px; height: 225px; ">
				<img src="http://#cgi.http_host#/userfiles/#application.clientId#/templates/#this.template#/template_#this.template#_07.png" width="20" height="225">
			</td>
			<td style=" width: 315px; height: 225px; background-image: url(/userfiles/#application.clientId#/templates/#this.template#/template_#this.template#_08.png); " class="drop315x225 areaClues" title="#request.secondaryClue#" id="area3039_form">
				<img src="http://#cgi.http_host#/userfiles/#application.clientId#/templates/#this.template#/template_#this.template#_08.png" width="315" height="225">
			</td>
		</tr>
		<tr>
			<td style=" width: 723px; height: 20px; " colspan="5">
				<img src="http://#cgi.http_host#/userfiles/#application.clientId#/templates/#this.template#/template_#this.template#_09.png" width="723" height="20">
			</td>
		</tr>
	</table>

</cfoutput>
	
<!--- template footer --->
<div class="foot">
	<img class="areaClues" title="<strong>Loyalty Points Footer</strong><br />This footer will be generated dynamically for each subscriber based on their Loyalty Club Points. Non-members will be invited to sign up." alt="" width="650" height="110" src="http://#cgi.http_host#/userfiles/#application.clientId#/e3d71ab3-3795-102c-9fa9-4fc2de14c7ac/images/Loyalty_Points_Footers/loyaltyFooter_animation.gif" />
	<p>This email was sent to: %%emailaddr%%</p>
	<p>This e-mail was sent by:</p>
	<p><a href="http://www.merchant.com" style="color: rgb(54, 54, 54); text-decoration: none;" target="_blank">%%Member_Busname%%</a>.</p>
	<p>%%Member_Addr%%</p>
	<p>%%Member_City%%, %%Member_State%%, %%Member_PostalCode%%, %%Member_Country%%</p>
	<p>Copyright &copy; [insert_year] %%Member_Busname%% All rights reserved.</p>
	<p><a href="http://merchant.com/ILoveMyMerchant/Login.cfm" style="color: rgb(54, 54, 54);" target="_blank">Update Profile</a> | <a href="%%ftaf_url%%" style="color: rgb(54, 54, 54);" target="_blank">Forward to a Friend</a> | <a href="http://merchant.com/Locations.cfm" style="color: rgb(54, 54, 54);" target="_blank">Locations</a> | <a href="http://merchant.com" style="color: rgb(54, 54, 54);" target="_blank">merchant.com</a></p>
	<p>Unsubscribe from: <a href="http://merchant.com/Unsubscribe.cfm?uid=E&e=%%emailaddr%%" style="color: rgb(54, 54, 54);" target="_blank">eClub</a></p>
	<p><a href="%%profile_center_url%%"><img width="1" height="1" border="0" src="http://<cfoutput>#cgi.http_host#</cfoutput>/ui/images/backGrounds/7dff89e3-f.gif" alt="spacer" style="display: block;" /></a></p>
</div>

Open in new window

0
 
LVL 52

Expert Comment

by:_agx_
Comment Utility
So #queryName.codeChunk# contains that entire block of code above? I wasn't sure because it contains </cfoutput> tags too.
0
 
LVL 1

Author Comment

by:brianmfalls
Comment Utility
It does.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 2

Accepted Solution

by:
aftershox earned 500 total points
Comment Utility
You could dynamically create a temporary file on the fly, and then cfinclude it back in.

<cffile action = "write"
   file = "tmpFile.cfm"
   output = "#queryName.codeChunk#">

<cfinclude template="tmpFile.cfm">

http://www.dopejam.com
0
 
LVL 2

Expert Comment

by:aftershox
Comment Utility
To add to that idea, if you're using CF9 you could try doing that with the VFS/RAM Disk capability that was introduced.
0
 
LVL 1

Author Closing Comment

by:brianmfalls
Comment Utility
I went with something similar...  (listed below)
0
 
LVL 1

Author Comment

by:brianmfalls
Comment Utility
I did what you suggested. (before you suggested it)  ;)  Only with a twist...
<div>
	<ul>
		<cfloop query="getEmailTemplates">
			<cfset request.templateData = application.template.getTemplate(templateID=#getEmailTemplates.layoutID#)>
			<cfset request.tempFileName = "/admin/" & request.thisModule & "/template." & numberFormat(getEmailTemplates.layoutID, "00000") & ".cfm">
			<cfset request.tempFileFullPath = "/var/www/shared.emtoobox.com/htdocs" & request.tempFileName>
			<cfset fileWrite(request.tempFileFullPath, request.templateData.html)>
			<li style=" list-style: none; display: inline; ">
				<img src="http://#cgi.http_host#/userfiles/#application.clientId#/templates/#numberFormat(getEmailTemplates.layoutID, "00000")#/preview.png" onclick="ColdFusion.navigate('#request.tempFileName#','ajaxContainer')" width="75" />
			</li>
		</cfloop>
	</ul>
</div>

<cfdiv id="ajaxContainer"></cfdiv>

Open in new window

0
 
LVL 52

Expert Comment

by:_agx_
Comment Utility
Sorry for the delay in responding.  I got caught up in meetings and it slipped my mind.. :(  Thanks for picking up the ball @aftershox!

0
 
LVL 1

Author Comment

by:brianmfalls
Comment Utility
Happens to us all.  :)
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

When setting up new project requests for our site, one of the most powerful tools our team has available to use is Axure (http://www.axure.com/). It’s a tool for creating software and web prototypes that can function and interact as if it were the a…
Objective of This Article In 1990’s, when I was a budding software professional, I had a lot of confusion about which stream or technology, I had to choose to build my career. In those days, I had lot of confusion like whether to choose System so…
The purpose of this video is to demonstrate how to set up an RSS Feed on a WordPress Website. This will be demonstrated using a Windows 8 PC. Feedburner will be used for this demonstration. Go to your WordPress login page. This will look like the…
The purpose of this video is to demonstrate how to set up the permalinks on a WordPress Website. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Go t…

762 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