Despite what nearly everyone says, dynamic includes may be possible in ASP. You just have to go through some effort to do so.
Dermis passes variables from ASP to the compiled Dermis file using session variables. It then shells to the compiled file using the server.execute("filename.asp") command. When you use the server.execute command, the called script cannot see variables (or code) from the parent (i.e., calling) script. However, session variables are outside of the variable space. So, Dermis can copy ASP variables into session variables, server.execute the script, return to the parent script, and delete the session variables.
(Incidentally, once the server.execute command finishes, the parent script can see its own variables again. Because of this, you can call sequential objT.display("filename.tpl") commands. But I digress...)
Right now, {include} compiles to <!--#include--!>. However, after a bit of searching, I found a site that has given me an idea. Using server.execute instead of #include may be a better solution, because you can have:
server.execute(strFilename)
server.execute(strDirectory & "/filename.tpl.asp")
server.execute(strDirectory & "/" & strLanguage & "/filename.tpl.asp")
...and such. However, the hard part will be how to compile an {include} file with variable components, because you don't know what the final filename will be until you run the code. (I think this is called "just in time" compiling.) Because we've shelled into a running script, and we can't see parent variables or code, I think the only solution is to somehow write the resolved filename to a session variable, exit the script, create the included file using the session variable, re-start the script, and go from there.
I have to think about this some more, but something in me tells me there's a way to do this!
Friday, November 20, 2009
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment