Solved

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

Posted on 2013-05-30
6
182 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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Hi. There are several upload tutorials using jquery and coldfusion. I found a very interesting one here Upload Your Files using Jquery & ColdFusion and Preview them (http://www.randhawaworld.com/) . I did keep the main js functions but made sever…
Recently while working on a project I got a very annoying cfdocument has no body error message. I had never seen this error before. So I checked the code. The code was pretty simple; it was Just showing me the cfdocumnt tag and inside that tag a …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

758 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

21 Experts available now in Live!

Get 1:1 Help Now