Solved

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

Posted on 2010-08-12
12
455 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_
ID: 33423901
Try using the evaluate() function. It should force an evaluation of the CF variables within the string.
0
 
LVL 1

Author Comment

by:brianmfalls
ID: 33424106
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_
ID: 33424160
Can you give a _small_ example of exactly what #queryName.codeChunk# looks like?
0
 
LVL 1

Author Comment

by:brianmfalls
ID: 33430208
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_
ID: 33434786
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
ID: 33445736
It does.
0
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 
LVL 2

Accepted Solution

by:
aftershox earned 500 total points
ID: 33460122
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
ID: 33460127
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
ID: 33465150
I went with something similar...  (listed below)
0
 
LVL 1

Author Comment

by:brianmfalls
ID: 33465159
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_
ID: 33476886
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
ID: 33477023
Happens to us all.  :)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
What is the Best Web Design Tool 1 55
TFS - Rolling back to a previous release / CRM 2011 8 113
I starting with php 12 117
Column Spacing 3 58
This article provides a case study on how our local youth baseball league deployed a new website, including the platform selection, implementation and benefits to the league.
Introduction In this tutorial, I'll explain how to create an animated progress meter in a wireframe prototype developed using Axure RP 7.0 - a leading prototyping tool for designing web sites and software. (For more information about Axure and gett…
The purpose of this video is to demonstrate how to insert an Iframe into WordPress. 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 : Open Page or Post…
The purpose of this video is to demonstrate how to reset a WordPress password if you are locked out and cannot reset the password. A typical use would be if you cannot access the email to which WordPress would send the password recovery email to…

867 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

23 Experts available now in Live!

Get 1:1 Help Now