Description
Saves the generated content of the cfsavecontent tag, including the results of evaluating expressions and executing custom tags, in the specified variable.
Category
History
ColdFusion (2021 release): Added a revised construct of saveContent in script syntax. See the example below for more details.
Syntax
<cfsavecontent variable = "variable name"> the content </cfsavecontent>
Also in ColdFusion (2021 release), the syntax of SaveContent has been revamped. For example,
myContent = savecontent{ writeOutput("Sample Content"); }
The new syntax gives you the ability to initialize the content inside a savecontent block to a LVAR, where LVAR can be a simple variable reference or an array/struct keys reference.
You can specify this tag's attributes in an attributeCollection attribute whose value is a structure. Specify the structure name in the attributeCollection attribute and use the tag's attribute names as structure keys.
See also
Caching parts of ColdFusion pages in Optimizing ColdFusion applications in the Developing ColdFusion Applications
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>
Example 2- in script syntax
<cfscript> result1 = savecontent { result2= savecontent { result3 = savecontent { WriteOutput("[inner1] savecontent "); } WriteOutput(result3 & "[inner2] savecontent "); } WriteOutput(result2 & "[outer] savecontent "); } WriteOutput(result1 & "<br>"); </cfscript>
Output
[inner1] savecontent [inner2] savecontent [outer] savecontent