Created
July 25, 2012 03:25
-
-
Save isapir/3174189 to your computer and use it in GitHub Desktop.
a custom tag for buffering content to be rendered at a later time, for example buffering all JS code to be rendered before the closing body tag.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!--- | |
usage: | |
<cf_BufferContent BufferId="beforeBodyEnd"> | |
javascript code goes here... | |
</<cf_BufferContent> | |
... then before the closing of the body tag: | |
<cf_BufferContent BufferId="beforeBodyEnd" Render="true"> | |
</body> | |
---> | |
<cfif StructKeyExists( Attributes, "disabled" )> | |
<cfexit method="EXITTAG"> <!--- not processing this tag at all; in case of a tag with open and close the content is skipped as well ---> | |
</cfif> | |
<cfparam name="Attributes.BufferId" default="default"> | |
<cfparam name="Attributes.Store" default="Request.waf.BufferedContent"> | |
<cfparam name="Attributes.RemoveWhitespace" default="#false#"> | |
<cfparam name="Attributes.Render" default="#false#"> | |
<cfset arrName = "#Attributes.Store#.#Attributes.BufferId#"> | |
<cfif thisTag.executionMode EQ 'Start'> | |
<cfif Attributes.Render> | |
<cfif IsDefined( "#arrName#" )> | |
<cfset arr = Evaluate( arrName )> | |
<cfloop array="#arr#" index="ai"> | |
<cfoutput>#ai#</cfoutput> | |
</cfloop> | |
<cfset "#arrName#" = ArrayNew( 1 )> | |
</cfif> | |
</cfif> | |
<cfelseif thisTag.executionMode EQ 'End'> | |
<cfif !IsDefined( "#arrName#" )> | |
<cfset "#arrName#" = ArrayNew( 1 )> | |
</cfif> | |
<cfset arr = Evaluate( arrName )> | |
<cfset htmlContent = thisTag.GeneratedContent> | |
<cfif Attributes.RemoveWhitespace> | |
<cfset htmlContent = REReplace( htmlContent, "\s+", " ", "all" )> | |
</cfif> | |
<cfset ArrayAppend( arr, htmlContent )> | |
<cfset thisTag.GeneratedContent = ""> | |
</cfif> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment