Skip to content

Instantly share code, notes, and snippets.

@adamcameron
Last active December 23, 2015 22:39
Show Gist options
  • Save adamcameron/6704259 to your computer and use it in GitHub Desktop.
Save adamcameron/6704259 to your computer and use it in GitHub Desktop.
Proof of concept of making a <cfoutput>-performing custom tag
Content before<br>
<cfset msg = "Content within">
<cf_withoutput callback="#toUpper#">
#msg#<br>
</cf_withoutput>
Content after<br>
<cfscript>
function toUpper(string){
return ucase(string);
}
</cfscript>
<cfscript>
if (thistag.executionMode == "END"){
structAppend(variables, caller);
thisDir = getDirectoryFromPath(getCurrentTemplatePath());
fileName = createUuid();
filePath = thisDir & fileName;
try {
fileWrite(filePath, "<cfoutput>" & thistag.generatedContent & "</cfoutput>");
savecontent variable="content"{
include fileName;
}
writeOutput(attributes.callback(content));
}
catch (any e){
rethrow;
}
finally {
if (fileExists(filePath)){
try {
fileDelete(filePath);
} catch(any ignore){
// oh well: I tried
}
}
}
thistag.generatedcontent = "";
}
</cfscript>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment