Skip to main content
Inspiring
December 21, 2018
Question

Timing of Page Output

  • December 21, 2018
  • 2 replies
  • 573 views

I have code like this

<cfoutput>#calculated_value# </cfoutput>

Then More code...................

Then the Calculations code is done here to get the calculated value.

Then More code...................

The issue I have is that I need to output the calculated_value before I calculate it later in the page.

I guess I could move the Calculations code to above the cfoutput, but it's not as easy as it sounds.

Is there a way for the entire page to load, but not output.... do the calculations code to get the calculated_value  and then output the entire page with the calculated_value  shown at the top?

    This topic has been closed for replies.

    2 replies

    BKBK
    Community Expert
    Community Expert
    December 22, 2018

    The solution, as you yourself say, is to place the code above the cfoutput line. Unless you mean there is more output between the calculations and "Then more".

    In that case, you could use a unique placeholder for 'calculated_value', then output the entire page content later. Something like this, the placeholder being the string [[<xyz>]]:

    <cfsavecontent variable="pageContent">

        [[<xyz>]]

        Then More code...................

        Then the Calculations code is done here to get the calculated value.

        <cfset calculated_value="abracadabra">

        Then More code...................

    </cfsavecontent>

    <cfset pageContent=replaceNoCase(pageContent, "[[<xyz>]]", calculated_value, "all")>

    <cfoutput>#pageContent#</cfoutput>

    WolfShade
    Legend
    December 21, 2018

    The only way that I can think of (and I'm sure others can think of other ways) would be to load the page, then use AJaX to call a CFC that will do the calculations and return the value(s).  Then you can use JavaScript to manipulate the DOM to display the results.

    HTH,

    ^ _ ^