Solved

How to ensure initial code is complete before calling other functions in Coldfusion

Posted on 2013-05-30
6
185 Views
Last Modified: 2013-09-06
I have Coldfusion code that is called via cfinclude template. I would like to ensure that the first templates have finished executing before I call the last one.  How do I do this?  

For example:
If my code looks something like:

<cfinclude template="template1.cfm">
<cfinclude template="template2.cfm">
<cfinclude template="template3.cfm">
<cfinclude template="template4.cfm">

I do not want to include the template template4.cfm until the other code is finished.
0
Comment
Question by:WestCoast_BC
  • 3
  • 2
6 Comments
 
LVL 2

Expert Comment

by:ravi_bachwala
ID: 39208260
Try this one:

Include the Template files prior to template file.

eg:-
Template1.cfm : <cfinclude template = "template2.cfm">
Template2.cfm : <cfinclude template ="template3.cfm">
Template3.cfm: <cfinclude template="template4.cfm">

This way when template one is loaded only template2.cfm would be loaded as template2 loads it would include template3 and so far.. include above lines on the templates at the end of the template files
0
 

Author Comment

by:WestCoast_BC
ID: 39208289
I could do that but the problem is that template2.cfm is used in other areas of the code where I don't want template3.cfm and template4.cfm called.
0
 
LVL 36

Expert Comment

by:SidFishes
ID: 39208719
all cfincludes operate as if they were loaded on the page that contains them. (ie: copy and paste everything from each file onto your master page.)

Ie; server assembles all the includes and then does any calculations...so functioanlly, they all "finish" at the same time.

You need to account for all setting & creation of variables in the code.

You can do things like

<cfif condition1 = x>
<cfinclude...>
<cfelse>
<Cfinclude...>
</cfif>

So shorter answer is you can't control the order in which they load as they are all loaded at once
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

Author Comment

by:WestCoast_BC
ID: 39217585
Could I do something like the following:

At the beginning of template1.cfm it set a variable to something like:
<cfset condition1 = true>

At the end of template1.cfm it set the variable to something like:
<cfset condition1 = false>

And then I could have something like the following:
<cfloop condition="condition1 eq true">
     Do nothing
</cfloop>
<cfinclude template="template2.cfm">

Would this work?

Thank you for any help you can provide.
0
 

Author Comment

by:WestCoast_BC
ID: 39237826
Can someone please comment on my suggestion above and let me know whether or not it will work

Thank you
0
 
LVL 36

Accepted Solution

by:
SidFishes earned 500 total points
ID: 39256812
Something like that should work - will depend on exactly what you are doing. give it a shot and let us know if you are having issues.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

PROBLEM:  How to open a cfwindow or run a function on double click of a cfgrid row. One of my clients wanted to be able to double click on a row item to get more detailed information about a transaction and to be able to modify the line items i…
I spent nearly three days trying to figure out how incorporate OAuth in Coldfusion for the Eventful API. Hopefully, this article will allow Coldfusion Programmers to buzz through the API when they need to. Basically, what this script does is authori…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now