Thanks for the approaches, Justin...

I'll give them a try.

Rick

-----Original Message-----
From: Justin Scott [mailto:leviat...@darktech.org] 
Sent: Thursday, September 15, 2011 11:38 AM
To: cf-talk
Subject: Re: Any way to process this within onRequest in Application.cfc?


> It seems that no matter how I try to do it, either putting
> js directly into an application.cfc or either using a cfinclude
> in an onRequest function, the js can't be processed along
> with the other code in the application.cfc.

A few options come to mind...

1) Wrap that output with CFSAVECONTENT, then use CFHTMLHEAD with that
variable and let ColdFusion insert the output into the head section of
the HTML that it output elsewhere.  This will work as long as you're
not using CFFLUSH on CFCONTENT with the reset attribute set to true
further along when processing the page.  This would look like...

<cfsavecontent variable="jsVars">
<script type="text/javascript">
var something = "#some value#";
</script>
</cfsavecontent>
<cfhtmlhead text="#jsVars#" />


2) Use the onRequestEnd() method in Application.cfc and manually
inject into the output stream.  This is similar to the first option,
but allows more control over where you want to inject the content into
the HTML.

<cffunction name="onRequestEnd" output="yes">
<cfargument type="string" name="targetPage" required="true" />
<cfset var generatedContent = getPageContext().getOut().getString() />
<!--- Put the cfsavecontent piece from above here to generate your
output to inject. --->
<!--- Write some code here to find where you want to insert it and
modify the generatedContent variable. --->
<cfcontent reset="yes" type="#variables.returnType#"
/><cfoutput>#generatedContent#</cfoutput><cfabort />
</cffunction>


3) Use the same CFSAVECONTENT snippet within onRequestStart or
onApplicationStart, whatever makes sense for you, but save it to a
request variable (e.g. request.jsVars) and then output that as part of
your standard "header" or "footer" display templates that other pages
might include.


-Justin



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:347489
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm

Reply via email to