Solved

Can you write code dynamically?

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

A Change in PHP Behavior with Session Write Short Circuit (http://php.net/manual/en/book.session.php#116217) (Winter 2014)** With the release of PHP 5.6 the session handler changed in a way that many think should be considered a bug.  See the note …
It’s a strangely common occurrence that when you send someone their login details for a system, they can’t get in. This article will help you understand why it happens, and what you can do about it.
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.
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to selectively show certain fields based on user input using rules to gather relevant information and data from your forms. The rules feature provides you with an opportunity…

773 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