'************************************** ' Name: Dynamic ASP include ' Description:This ASP function replaces ' the standard "include" statement, allowi ' ng a TRUE working dynamic include in cla ' ssic ASP. Included files can contain a mix of vbscript / HTML / javascript. Usage is really easy: <% Include("included.asp") %> ' By: TFI ' ' ' Inputs:None ' ' Returns:None ' 'Assumes:None ' 'Side Effects:None '************************************** <% ' **** Dynamic ASP include v.2.2 ' **** by TFI Function fixInclude(content) out="" content=regreplace(content,"<!-- *# *include file *= *""(.+)"" *-->","<"&"%include(""$1"")%"&">",false) 'content=regreplace(content,"<!-- *# *in ' clude virtual *= *"".+"" *-->","<BR><fon ' t color=red><B>ERROR: 'include virtual' ' not supported!</B></font><BR>",false) content=replace(content,"<"&"%=","<"&"%response.write ") content=replace(content,"<"&"% =","<"&"%response.write ") 'content=regreplace(content,"<"&"% *= *" ' ,"<"&"%response.write ",false) 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 regreplace(strOriginalString, strPattern, strReplacement, varIgnoreCase) dim objRegExp : set objRegExp = new RegExp with objRegExp .Pattern = strPattern .IgnoreCase = varIgnoreCase .Global = True end with regreplace = objRegExp.replace(strOriginalString, strReplacement) set objRegExp = nothing 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 Function Include(filename) executeglobal (fixInclude(getMappedFileAsString(filename))) End Function %> <!-- Example of usage: --> <% Include("included.asp") %>