Solved

Can you write code dynamically?

Posted on 2008-10-14
2
220 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
Comment Utility
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
Comment Utility
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 to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Using Quotation Marks in PHP This question (http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_28217211.html) seems to come up a lot for developers who are new to PHP.  And it got me thinking, "How can we explain the rule…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This video teaches viewers how to create their own website using cPanel and Wordpress. Tutorial walks users through how to set up their own domain name from tools like Domain Registrar, Hosting Account, and Wordpress. More specifically, the order in…
This video teaches users how to migrate an existing Wordpress website to a new domain.

743 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

18 Experts available now in Live!

Get 1:1 Help Now