Highlighted

Timing of Page Output

Participant ,
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

335

Likes

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

Timing of Page Output

Participant ,
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

336

Likes

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
Dec 21, 2018 0
LEGEND ,
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,

^ _ ^

Likes

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
Reply
Loading...
Dec 21, 2018 0
BKBK LATEST
Adobe Community Professional ,
Dec 21, 2018

Copy link to clipboard

Copied

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>

Likes

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
Reply
Loading...
Dec 21, 2018 0