Stopping cfsavecontent from evaluating CF tags

I want to save some page content to a variable and I also want to include any coldfusion tags rather then have them be evaluated. Is this possible?

I currently create the content like this and it works ok but I would prefer to be able to tell the savecontent tag not to process the cf tags in certain areas:

<cfsavecontent variable="myVar">
text text <%cfoutput%>#myvar#<%/cfoutput%>
</cfcsavecontent>

<cfset myVar =replaceList(myVar,"<%,</%,%>", "<,</,>")>
LVL 1
rot299Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
mosphatConnect With a Mentor Commented:
It's not cfsavecontent that is processing ColdFusion tags, it's the ColdFusion application server that is processing them. And there is no way to have ColdFusion not process ColdFusion tags.
If you want to create cfm files, you might want to try this approach:

<cfset x = "<">
<cfsavecontent variable="myVar">
test test #x#cfoutput>##anotherVar###x#/cfoutput>
</cfcsavecontent>

You simply build replace every '<' that starts a ColdFusion tag with the variable x.
This way you don't have to replace anything afterwards and myVar will contain: test test <cfoutput>#anotherVar#</cfoutput>, which in turn you can write to a file.

HTH,
Ruud

0
 
anandkpCommented:
u cld try replacing the < with "&lt;" & > with "&gt;"
0
 
Renante EnteraSenior PHP DeveloperCommented:
Hello rot299!

Actually, there's no problem on your code.  But if you wish to get the value of the variable "myvar", simply use CF Function HTMLEditFormat().

You can try running this code :
  <cfoutput>#HTMLEditFormat(myvar)#</cfoutput>

So, you can change your code into something like this :
  <cfset myVar = HTMLEditFormat(replaceList(myVar,"<%,</%,%>", "<,</,>"))>

Hope this helps.  Just try it.


Goodluck!
eNTRANCE2002 :-)
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
Renante EnteraSenior PHP DeveloperCommented:
In addition to that, kindly review your code.

An error ("Context validation error for tag cfcsavecontent") will be expected to occur on the line :
   </cfcsavecontent>


Regards!
eNTRANCE2002 :-)
0
 
rot299Author Commented:
Thanks for your help so far. My example wasn't to clear so ill re-do it:

<cfsavecontent variable="myVar">
text text <%cfoutput%>##anotherVar##<%/cfoutput%>
</cfcsavecontent>

<cfset myVar =replaceList(myVar,"<%,</%,%>", "<,</,>")>

The whole idea is that I want the following to be the final value of myVar which will then be written to a file to create a .cfm page:

test test <cfoutput>#anotherVar#</cfoutput>


So basically I want to tell cfsavecontent not to process some coldfusion tags, but actually save them as a string in the var "myVar". The tricky thing is I do need to process some sections of the cf content so I need some way switching the savecontent tags state. My current way works but I just wanted to know if there way a more elegant way to do it already build into cf.

0
 
Jerry_PangCommented:
i do not have coldfusion here so i could not test this. anyways please try this

use the delay evalaution - de()

<cfsavecontent variable="myVar">
de("text text <cfoutput>#anotherVar#</cfoutput>")
</cfcsavecontent>

jerry
0
 
mosphatCommented:
DE() is an option as well, but you have to double the pound signs like this for it to work:

<cfsavecontent variable="myVar">
#de("text text <cfoutput>##anotherVar##</cfoutput>")#
</cfsavecontent>

However, if you need some tags to be valuated (like below), it might turn into messy code, because of a lot of DE()'s. And I'm not sure what a lot of DE()'s do to performance.

<cfsavecontent variable="myVar">
#de("text text <cfoutput>##anotherVar##</cfoutput>")#
<cfif blah eq thisAndThat>
#de("another bit of <cfoutput>##blah##</cfoutput>")
</cfif>
</cfsavecontent>

Besides, if you're using CF Studio/Homesite, colorcoding will highlight the tags in the string as well and make this harder to read.
0
All Courses

From novice to tech pro — start learning today.