I mean, like php'h include...
我的意思是,像php'h包括......
something like
my_file_to_be_included = "include_me.asp" -- >
for what I've seen so far, there are a couple of alternatives, but every one of them has some sort of shortcoming...
对于我到目前为止看到的,有几种选择,但每一种都有某种缺点......
what I'm trying to figure out is how to make a flexible template system... without having to statically include the whole thing in a single file with a loooooong case statement...
我想弄清楚的是如何制作一个灵活的模板系统......而不必将整个东西静态地包含在一个带有loooooong case语句的单个文件中......
here there are a couple of links
这里有几个链接
a solution using FileSysmemObject, just lets you include static pages
使用FileSysmemObject的解决方案,只允许您包含静态页面
还有一个
来自土坯的同样的事情
this approach uses Server.Execute
这种方法使用Server.Execute
but it has some shortcomings I'd like to avoid... seems like (haven't tried yet) Server.Execute code runs in another context, so you can't use it to load a functions your are planning to use in the caller code... nasty...
但它有一些我想要避免的缺点...似乎(尚未尝试)Server.Execute代码在另一个上下文中运行,因此您无法使用它来加载您计划在来电代码...讨厌......
我觉得这个是一样的
看起来很有希望!!!
I'm not sure about it (couldn't test it yet) but it seems like this one dinamycally handles the page to a SSDI component...
我不确定它(无法测试它)但似乎这个dinamycally处理页面到SSDI组件...
any idea???
6 个解决方案
#1
No you can't do a dyanmic include, period.
不,你不能做一个dyanmic包括,期间。
Your best shot at this is a server.execute and passing whatever state it needs via a Session variable:-
你最好的一点是server.execute并通过Session变量传递它需要的任何状态: -
Session("callParams") = BuildMyParams() 'Creates some sort of string
Server.Execute(my_file_to_be_included)
Session.Contents.Remove("callParams")
#2
Improved version (v2.0):
改进版(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")))
%>
#3
Sure you can do REAL classic asp dynamic includes. I wrote this a while back and it has opened up Classic ASP for me in a whole new way. It will do exactly what you are after, even though people seem to think it isn't possible!
当然你可以做真正的经典asp动态包括。我写了一段时间后,它以一种全新的方式为我打开了经典ASP。即使人们似乎认为不可能,它也会完全符合您的要求!
Any problems just let me know.
任何问题都让我知道。
#4
I'm a bit rusty on classic ASP, but I'm pretty sure you can use the Server.Execute
method to read in another asp page, and then carry on executing the calling page. 15Seconds had some basic stuff about it - it takes me back ...
我在经典ASP上有点生疏,但我很确定你可以使用Server.Execute方法读取另一个asp页面,然后继续执行调用页面。 15秒有一些基本的东西 - 它带我回来......
#5
I am building a web site where it would have been convenient to be able to use dynamic includes. The site is all ajax (no page reloads at all) and while the pure-data JSON-returning calls didn't need it, all the different html content for each different application sub-part (window/pane/area/form etc) seems best to me to be in different files.
我正在建立一个网站,在那里可以方便地使用动态包含。该网站都是ajax(根本没有页面重新加载),而纯数据JSON返回调用不需要它,每个不同的应用程序子部分(窗口/窗格/区域/窗体等)的所有不同的html内容对我来说最好是在不同的文件中。
My initial idea was to have the ajax call be back to the "central hub" main file (that kicks the application off in the first place), which would then know which sub-file to include. Simply including all the files was not workable after I realized that each call for some possibly tiny piece would have to parse all the ASP code for the entire site! And using the Execute method was not good, both in terms of speed and maintenance.
我最初的想法是让ajax调用回到“中心集线器”主文件(首先关闭应用程序),然后知道要包含哪个子文件。在我意识到每次调用一些可能很小的部分都需要解析整个站点的所有ASP代码之后,简单地包含所有文件是行不通的!在速度和维护方面,使用Execute方法并不好。
I solved the problem by making the supposed "child" pages the main pages, and including the "central hub" file in each one. Basically, it's a javascript round-trip include.
我通过将所谓的“子”页面作为主页面来解决问题,并在每个页面中包含“中心集线器”文件。基本上,这是一个javascript往返包括。
This is less costly than it seems since the whole idea of a web page is that the server responds to client requests for "the next page" all the time. The content that is being requested is defined in scope by the page being called.
由于网页的整体构思是服务器始终响应客户端对“下一页”的请求,因此这比看起来要便宜。正在请求的内容由被调用的页面在范围内定义。
The only drawback to this is that the "web pieces" of the application have to live partly split apart: most of their content in a real named .asp file, but enough of their structure and relationship defined in the main .asp file (so that, for example, a menu item in one web piece knows the name to use to call or load another web piece and how that loading should be done). In a way, though, this is still an advantage over a traditional site where each page has to know how to load every other page. Now, I can do stuff like "load this part (whether it's a whole page or otherwise) the way it wants to be loaded".
唯一的缺点是应用程序的“Web部件”必须部分拆分:它们的大部分内容都在一个真正命名的.asp文件中,但在主.asp文件中定义了足够的结构和关系(所以例如,一个网页中的菜单项知道用于调用或加载另一个网页的名称以及应该如何进行加载。但是,在某种程度上,这仍然优于传统网站,每个网页都必须知道如何加载其他每个网页。现在,我可以做一些事情,比如“加载这个部分(无论是整页还是其他部分)”。
I also set it up so each part can have its own javascript and css (if only that part needs those things). Then, those files are included dynamically through javascript only the first time that part is loaded. Then if the part is loaded repeatedly it won't incur an extra overhead.
我也设置了它,所以每个部分都可以拥有自己的javascript和css(如果只有那部分需要那些东西)。然后,只有在第一次加载该部分时,才会通过javascript动态包含这些文件。然后,如果零件重复加载,则不会产生额外的开销。
#6
Just as an additional note. I was getting weird ASCII characters at the top of the pages that were using dynamic includes so I found that using an ADODB.Stream object to read the include file eliminated this issue.
就像另外一个注释。我在使用动态包含的页面顶部得到了奇怪的ASCII字符,所以我发现使用ADODB.Stream对象读取包含文件消除了这个问题。
So my updated code for the getMappedFileAsString function is as follows
所以我更新的getMappedFileAsString函数代码如下
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
#1
No you can't do a dyanmic include, period.
不,你不能做一个dyanmic包括,期间。
Your best shot at this is a server.execute and passing whatever state it needs via a Session variable:-
你最好的一点是server.execute并通过Session变量传递它需要的任何状态: -
Session("callParams") = BuildMyParams() 'Creates some sort of string
Server.Execute(my_file_to_be_included)
Session.Contents.Remove("callParams")
#2
Improved version (v2.0):
改进版(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")))
%>
#3
Sure you can do REAL classic asp dynamic includes. I wrote this a while back and it has opened up Classic ASP for me in a whole new way. It will do exactly what you are after, even though people seem to think it isn't possible!
当然你可以做真正的经典asp动态包括。我写了一段时间后,它以一种全新的方式为我打开了经典ASP。即使人们似乎认为不可能,它也会完全符合您的要求!
Any problems just let me know.
任何问题都让我知道。
#4
I'm a bit rusty on classic ASP, but I'm pretty sure you can use the Server.Execute
method to read in another asp page, and then carry on executing the calling page. 15Seconds had some basic stuff about it - it takes me back ...
我在经典ASP上有点生疏,但我很确定你可以使用Server.Execute方法读取另一个asp页面,然后继续执行调用页面。 15秒有一些基本的东西 - 它带我回来......
#5
I am building a web site where it would have been convenient to be able to use dynamic includes. The site is all ajax (no page reloads at all) and while the pure-data JSON-returning calls didn't need it, all the different html content for each different application sub-part (window/pane/area/form etc) seems best to me to be in different files.
我正在建立一个网站,在那里可以方便地使用动态包含。该网站都是ajax(根本没有页面重新加载),而纯数据JSON返回调用不需要它,每个不同的应用程序子部分(窗口/窗格/区域/窗体等)的所有不同的html内容对我来说最好是在不同的文件中。
My initial idea was to have the ajax call be back to the "central hub" main file (that kicks the application off in the first place), which would then know which sub-file to include. Simply including all the files was not workable after I realized that each call for some possibly tiny piece would have to parse all the ASP code for the entire site! And using the Execute method was not good, both in terms of speed and maintenance.
我最初的想法是让ajax调用回到“中心集线器”主文件(首先关闭应用程序),然后知道要包含哪个子文件。在我意识到每次调用一些可能很小的部分都需要解析整个站点的所有ASP代码之后,简单地包含所有文件是行不通的!在速度和维护方面,使用Execute方法并不好。
I solved the problem by making the supposed "child" pages the main pages, and including the "central hub" file in each one. Basically, it's a javascript round-trip include.
我通过将所谓的“子”页面作为主页面来解决问题,并在每个页面中包含“中心集线器”文件。基本上,这是一个javascript往返包括。
This is less costly than it seems since the whole idea of a web page is that the server responds to client requests for "the next page" all the time. The content that is being requested is defined in scope by the page being called.
由于网页的整体构思是服务器始终响应客户端对“下一页”的请求,因此这比看起来要便宜。正在请求的内容由被调用的页面在范围内定义。
The only drawback to this is that the "web pieces" of the application have to live partly split apart: most of their content in a real named .asp file, but enough of their structure and relationship defined in the main .asp file (so that, for example, a menu item in one web piece knows the name to use to call or load another web piece and how that loading should be done). In a way, though, this is still an advantage over a traditional site where each page has to know how to load every other page. Now, I can do stuff like "load this part (whether it's a whole page or otherwise) the way it wants to be loaded".
唯一的缺点是应用程序的“Web部件”必须部分拆分:它们的大部分内容都在一个真正命名的.asp文件中,但在主.asp文件中定义了足够的结构和关系(所以例如,一个网页中的菜单项知道用于调用或加载另一个网页的名称以及应该如何进行加载。但是,在某种程度上,这仍然优于传统网站,每个网页都必须知道如何加载其他每个网页。现在,我可以做一些事情,比如“加载这个部分(无论是整页还是其他部分)”。
I also set it up so each part can have its own javascript and css (if only that part needs those things). Then, those files are included dynamically through javascript only the first time that part is loaded. Then if the part is loaded repeatedly it won't incur an extra overhead.
我也设置了它,所以每个部分都可以拥有自己的javascript和css(如果只有那部分需要那些东西)。然后,只有在第一次加载该部分时,才会通过javascript动态包含这些文件。然后,如果零件重复加载,则不会产生额外的开销。
#6
Just as an additional note. I was getting weird ASCII characters at the top of the pages that were using dynamic includes so I found that using an ADODB.Stream object to read the include file eliminated this issue.
就像另外一个注释。我在使用动态包含的页面顶部得到了奇怪的ASCII字符,所以我发现使用ADODB.Stream对象读取包含文件消除了这个问题。
So my updated code for the getMappedFileAsString function is as follows
所以我更新的getMappedFileAsString函数代码如下
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