Dynamic ASP include

ASP function replaces the standard "include" statement, allowing a TRUE working dynamic include in classic ASP.
' Included files can contain a mix of vbscript / HTML / javascript.
' Usage is really easy: <% Include("included.asp") %>
' Source = http://www.planet-source-code.com/vb/scripts/ShowCode.asp?lngWId=4&txtCodeId=9796
' By: TFI

'**************************************
' Name: Dynamic ASP include
' Description:This ASP function replaces the standard "include" statement, allowing a TRUE working dynamic include in classic ASP.
' Included files can contain a mix of vbscript / HTML / javascript.
' Usage is really easy: <% Include("included.asp") %>
' Source = http://www.planet-source-code.com/vb/scripts/ShowCode.asp?lngWId=4&txtCodeId=9796
' By: TFI
' Inputs:None
' Returns:None
' Assumes:None
' Side Effects:None
'**************************************
<%
' **** Dynamic ASP include v.2.2
' **** by TFI
Function Include(filename)
 executeglobal (fixInclude(getMappedFileAsString(filename)))
End Function
Function fixInclude(content)
 out      = ""
 content     = regreplace(content,"<!-- *# *include file *= *""(.+)"" *-->","<"&"%include(""$1"")%"&">",false)
 'content     = regreplace(content,"<!-- *# *include virtual *= *"".+"" *-->","<BR><font 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


%>
<!-- Example of usage: -->
<% Include("included.asp") %>



  

filename

<% Include(&#34;included.asp&#34;) %>

Views 430 Downloads 179

'include', 'classic', 'dymanic', 'insert', 'embed', 'inherit', 'NotMyWork', 'NotTestedYet', 'NotTested'

ANmarAmdeen
448
Components Classic ASP
Revisions

v1.0