Solved

Can you write code dynamically?

Posted on 2008-10-14
2
224 Views
Last Modified: 2010-05-18
Instead of writing a series of if statements, I'd like to dynamically loop over a query and have the code written to the template at run time...so in stead of writing a bunch of:

<cfif condition>do this</cfif>
<cfif condition>do this</cfif>

statements in the template I'd rather do this:

<cfloop query="somequery">
<cfif fieldname>do this</cfif>
</cfloop>

and write this to the template...

Is this possible?

0
Comment
Question by:cfmdev
[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
2 Comments
 

Author Comment

by:cfmdev
ID: 22719568
Perhaps a solution to this problem would be to write the results of the query to a file and then in the template where I would have hard-coded the conditionals, read the file and then output the results on the page as text? Not sure...was hoping someone had done this before...
0
 
LVL 70

Accepted Solution

by:
Jason C. Levine earned 500 total points
ID: 22725984
I don't think what you want to do in the original question is possible unless you force the page through a command line script prior to it being served.  Once the processor begins to read the script, it cannot really stop to write new code based on the conditionals.  Eval an if statement, yes.  Affect HTML or SQL, yes.  Rewrite itself, not so much.

Your second method should work.  First call fires a query which writes the external file and sets a session so you know not to refire the query.  Next call checks the session and skips over to the include call.
0

Featured Post

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Thoughout my experience working on eCommerce web applications I have seen applications succumbing to increased user demand and throughput. With increased loads the response times started to spike, which leads to user frustration and lost sales. I ha…
This video teaches users how to migrate an existing Wordpress website to a new domain.
Learn how to set-up PayPal payment integration in your Wufoo form. Allow your users to remit payment through PayPal upon completion of your online form. This is helpful for collecting membership payments, customer payments, donations, and more.

738 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