Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2013-05-30
6
Medium Priority
?
204 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
[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

 

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 2000 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article  is about submitting  form through  ColdFusion.Ajax.submitForm to the action page and send a response back in JSON format which later can be decoded using ColdFusion.JSON.decode. By this way you can avoid the usual page refresh for subm…
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 …
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

876 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