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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
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
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Servers

From novice to tech pro — start learning today.