Can i enable dynamic inclusion in asp-classic?
I mean how php'h enable ...
something like
my_file_to_be_included = "include_me.asp" ->
for what I have seen so far, there are several alternatives, but each of them has a kind of disadvantage ...
I am trying to figure out how to create a flexible template system ... without having to statically include all this in one file using the loooooong case statement ...
there are several links here
solution using FileSysmemObject, just allows you to include static pages
this approach uses Server.Execute
but it has some flaws that I would like to avoid ... it seems (I have not tried it yet). Server. The execute code is executed in a different context, so you cannot use it to load functions that you plan to use in the caller’s code ... nasty ...
I'm not sure about this (I have not been able to check it yet), but it looks like this one is dynamically processing the page to the SSDI component ...
any idea ???
No, you cannot include dyanmic include, period.
Your best snapshot on this is server.execute and passing any state it needs using the Session variable: -
Session("callParams") = BuildMyParams() 'Creates some sort of string Server.Execute(my_file_to_be_included) Session.Contents.Remove("callParams") Improved Version (v2.0):
<% ' **** Dynamic ASP include v.2.0 function fixInclude(content) out="" if instr(content,"#include ")>0 then response.write "Error: include directive not permitted!" response.end end if content=replace(content,"<"&"%=","<"&"%response.write ") pos1=instr(content,"<%") pos2=instr(content,"%"& ">") if pos1>0 then before= mid(content,1,pos1-1) before=replace(before,"""","""""") before=replace(before,vbcrlf,""""&vbcrlf&"response.write vbcrlf&""") before=vbcrlf & "response.write """ & before & """" &vbcrlf middle= mid(content,pos1+2,(pos2-pos1-2)) after=mid(content,pos2+2,len(content)) out=before & middle & fixInclude(after) else content=replace(content,"""","""""") content=replace(content,vbcrlf,""""&vbcrlf&"response.write vbcrlf&""") out=vbcrlf & "response.write """ & content &"""" end if fixInclude=out end function Function getMappedFileAsString(byVal strFilename) Dim fso,td Set fso = Server.CreateObject("Scripting.FilesystemObject") Set ts = fso.OpenTextFile(Server.MapPath(strFilename), 1) getMappedFileAsString = ts.ReadAll ts.close Set ts = nothing Set fso = Nothing End Function execute (fixInclude(getMappedFileAsString("included.asp"))) %> Of course you can make REAL classic asp dynamic include . I wrote this a while ago, and he discovered Classic ASP for me in a completely new way. He will do what you need, although people seem to think that this is impossible!
Any problems just let me know.
I'm a little rusty on classic ASP, but I'm sure you can use the Server.Execute method to read on another asp page and then continue to execute the calling page. 15Seconds had some basic things about it - it brings me back ...
I am creating a website where it would be convenient to use dynamic features. Everything is ajax on the site (the page does not reload at all), and while JSON requests returning clean data did not need it, all the different html content for each individual part of the application (window / region / region / form, etc. .), It seems to me better to be in different files.
My initial idea was to return an ajax call to the main file of the "central hub" (which first deletes the application), which then finds out which of the subfiles should be included. Just including all the files was not workable after I realized that every call for some, possibly tiny part, would have to analyze all the ASP code for the whole site! And using the Execute method was not good, both in terms of speed and maintenance.
I solved the problem by making the alleged "child" pages the main pages, including the "central hub" file in each of them. Basically, this includes javascript round-trip.
This is cheaper than it seems, since the whole idea of a web page is that the server constantly responds to client requests for the "next page". The requested content is defined in the area using the called page.
The only drawback of this is that the "web fragments" of the application must be partially separated: most of their contents are in the real named .asp file, but their structure and relations, defined mainly in the .asp file (for example, a menu item in one the web fragment knows the name that will be used to call or load another web fragment and how this download should be performed). In a way, this is still an advantage over a traditional site where every page should know how to load every other page. Now I can do things like "load this part (whether it's a whole page or otherwise) the way it wants to be loaded."
I also set it up so that each part can have its own javascript and css (if only this part needs these things). Then, these files are dynamically included through javascript only when this part is first loaded. Then, if the part is reloaded, it will not incur additional overhead.
As an additional note. I was getting weird ASCII characters at the top of pages using dynamic inclusions, so I found that using the ADODB.Stream object to read the included file fixes this problem.
So my updated code for getMappedFileAsString function is as follows
Function getMappedFileAsString(byVal strFilename) Dim fso Set fso = CreateObject("ADODB.Stream") fso.CharSet = "utf-8" fso.Open fso.LoadFromFile(Server.MapPath(strFilename)) getMappedFileAsString = fso.ReadText() 'Response.write(getMappedFileAsString) 'Response.End Set fso = Nothing End Function