Solved

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

Posted on 2013-05-30
6
198 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
How our DevOps Teams Maximize Uptime

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

 

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

Is Your DevOps Pipeline Leaking?

Is your CI/CD pipeline a hodge-podge of randomly connected tools? You’ve likely got a tool to fix one problem & then a different tool to fix another, resulting in a cluster of tools with overlapping functionality. Learn how to optimize your pipeline with Gartner's recommendations

Question has a verified solution.

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

Suggested Solutions

The technique is by far very Simple! How we can export the ColdFusion query results to DOC file?  Well before writing this I researched a lot in Internet but did not found a good Answer anyways!  So i thought now i should share my small snippet w…
Hi, Even though I have created this Tutorial on My personal Blog, Some people might not able to find my website, So here i am posting it again Today, from the topic it is very clear that i will be showing you here the very basic usage of how we …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

752 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