Solved

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

Posted on 2010-08-12
12
459 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
[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
  • 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
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 
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
 
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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Turn A Profile Picture Into A Cartoon Using Photoshop And Illustrator This tutorial will teach you how to make a cartoon style image out of a regular picture. I have tried to keep the tutorial as simple as possible. I used Adobe CS4 for this tuto…
This guide will walk you through the essential considerations and tech stack for building scalable websites. Know how to grow your business the smart way!
The purpose of this video is to demonstrate how to connect a WordPress website to Google Analytics. 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 :…
The purpose of this video is to demonstrate how to integrate Mailchimp with Facebook. This will be demonstrated using a Windows 8 PC. Mailchimp and Facebook will be used. Log into your Mailchimp account. : Click on your name. Go to Account Setti…

749 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