Solved

Can you write code dynamically?

Posted on 2008-10-14
2
221 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Release hotel wifi password only after customer review: is it possible? 19 62
Search on a site 5 94
WCAG audit tools 1 72
Re-imbursement Claim System 3 53
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…
If I have to fix slow responding website my first thoughts are server side optimizations: the database may not be optimized or caching is not enabled, or things like that. We often overlook another major part of our web application: the client. We o…
This video teaches users how to migrate an existing Wordpress website to a new domain.
Wufoo.com provides powerful tools for surveying targeted groups, and utilizing data from completed surveys to find trends, discover areas of demand or customer expectation, and make business decisions on products or services.

896 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

11 Experts available now in Live!

Get 1:1 Help Now