|
-
May 29th, 2000, 10:02 PM
#1
Thread Starter
Addicted Member
I want to let my users paste in some text as an include file for their page.
When I then display their page I want to include this file.
If I were to include a static include file the HTML would be:
Code:
<!--#include virtual=".../filename.inc" -->
but I want to dynamically specify this filename with some ASP, something like:
Code:
<!-- #include virtual=".../include_<%=firstname>_<%=lastname%>.inc" -->
Problem is, the ASP does not get processed because it is encased in a comment.
I have not been able to think of a workaround...
suggestions?
tx
-
May 29th, 2000, 10:18 PM
#2
Frenzied Member
How about:
<%
dim quote
quote = chr(34)
Response.Write "<!-- #include virtual=" & quote & ".../include_" & firstname & "_" & lastname & ".inc" & quote & "-->"
%>
-
May 29th, 2000, 10:29 PM
#3
Thread Starter
Addicted Member
nice
good call mark.
i feel dumb..shoulda thought of that!!
thanx
-
May 29th, 2000, 10:33 PM
#4
Frenzied Member
-
May 30th, 2000, 12:12 AM
#5
Thread Starter
Addicted Member
i'll try to manage
-
May 30th, 2000, 02:55 AM
#6
Thread Starter
Addicted Member
DID NOT WORK
hey mark..
i tried it out, and it didn't work...
I have the following (ugly--but correct) statement in my ASP
Code:
<%
Response.Write "<!-- #include virtual="&chr(34)&"/EmployeeHomepages/"&fn&"_"&ln&"/include_"&fn&"_"&ln&".inc"&chr(34)&" -->"
%>
But when the page loads, I see the following statement in the source:
Code:
<!-- #include virtual="/EmployeeHomepages/testxy_case/include_testxy_case.inc" -->
It's not a good sign that I see this in the source--it should be the stuff in the file!
HOWEVER, when I paste the statement given above (in the second code block) as static html it works fine.
I think the problem here has to do with when the html it produced by the server....
I don't know how to get around this.... ideas?
tx
-
May 30th, 2000, 03:33 AM
#7
Thread Starter
Addicted Member
SOLVED
found a solution:
http://www.activeserverpages.com/lea...udedynamic.asp
it works!!!
I don't understand why though....
If someone looks at it and understands it, could you maybe tell me what's going on.
tx
-
Nov 22nd, 2012, 05:04 AM
#8
New Member
Re: SOLVED
This code works pretty well (Dynamic ASP include by TFI): 
Code:
<%
' **** Dynamic ASP include v.2.2
' **** by TFI
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
Function Include(filename)
executeglobal (fixInclude(getMappedFileAsString(filename)))
End Function
%>
<!-- Example of use: -->
<% Include("included.asp") %>
-
Nov 26th, 2012, 09:29 PM
#9
New Member
Re: Dynamic include file in ASP
 Originally Posted by dvst8
I want to let my users paste in some text as an include file for their page.
When I then display their page I want to include this file.
If I were to include a static include file the HTML would be:
Code:
<!--#include virtual=".../filename.inc" -->
but I want to dynamically specify this filename with some ASP, something like:
Code:
<!-- #include virtual=".../include_<%=firstname>_<%=lastname%>.inc" -->
Problem is, the ASP does not get processed because it is encased in a comment.
I have not been able to think of a workaround...
suggestions?
tx
I also had this problem. Thanks for this great post!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|