View comments | RSS feed

cfsavecontent

Description

Saves the generated content of the cfsavecontent tag, including the results of evaluating expressions and executing custom tags, in the specified variable.

Category

Variable manipulation tags

Syntax

<cfsavecontent 
variable = "variable name">
the content
</cfsavecontent>

See also

Caching parts of ColdFusion pages in Designing and Optimizing a ColdFusion Application in ColdFusion MX Developer's Guide

Attributes

Attribute Req/Opt Default Description

variable

Required

 

Name of the variable in which to save the generated content of the tag.

Usage

This tag requires an end tag.

You cannot use this tag to suppress output from a tag library.

Example

The following example uses a custom tag to generate a report and saves the report in the variable CONTENT. It replaces all instances of the word "report" with the phrase "MyCompany Quarterly Report" and outputs the result.

<cfsavecontent variable="content">
   <CF_OutputBigReport>
</cfsavecontent>
<cfoutput>
   #replace(content, "report", "MyCompany Quarterly Report", "all")#
</cfoutput>

ColdFusion 9 | ColdFusion 8 | ColdFusion MX 7 | ColdFusion MX 6.1 | ColdFusion MX | Forums | Developer Center | KnowledgeBase | Bug Reporting

Version 7

Comments


No screen name said on Sep 26, 2005 at 8:45 AM :
you must have <cfsetting enablecfoutputonly="no"> OR must surround all contents by a cfoutput If using cfsavecontent to extend flash based cfforms, or any other usage of this tag where the actual text of the contents is needed (not neccesarily running cfcode within it).

again, seems redundant to some, but this problem bugged me for a few hours not realizing why my actionscript wasnt executing.

(this is copied from the 6.1 livedocs)
CF_Doctor said on Jul 24, 2006 at 12:56 PM :
Here's an example of displaying the currently running query on screen:

<cfquery name="test" datasource="testDB">
<cfsavecontent variable="myQuery">
SELECT userID, first, last, status
FROM tableA
WHERE status = 'Active'
<cfif isdefined("url.alpha")>
AND LEFT(last, 1) = '#url.alpha#'
</cfif>
</cfsavecontent>
#preservesinglequotes(myQuery)#
</cfquery>

<cfoutput>#preservesinglequotes(myQuery)#</cfoutput>
<!---------------------------------end code--------------------------------------->

This is most useful when using conditionals to filter data in your query and not knowing which filter is currently active.

Cheers!
boughtonp said on Apr 3, 2007 at 5:42 AM :
NOTE: cfsavecontent does not support bracket notation.

So whilst you can do:
<cfsavecontent variable="Request.TestVar">
or <cfsavecontent variable="Request.#VarName#">

You CANNOT do:
<cfsavecontent variable="Request['TestVar']">
or <cfsavecontent variable="Request[VarName]">

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/coldfusion/7/htmldocs/00000327.htm