• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Timing of Page Output

Participant ,
Dec 21, 2018 Dec 21, 2018

Copy link to clipboard

Copied

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?

Views

474

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 21, 2018 Dec 21, 2018

Copy link to clipboard

Copied

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,

^ _ ^

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 21, 2018 Dec 21, 2018

Copy link to clipboard

Copied

LATEST

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>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation