asp 동적include 파일, 다중 템플릿 구현

1150 단어
매크로의 제한을 받아 이 파일이 존재하고 미리 컴파일됩니다. (앞에 조건이 있든 없든)
항상 이런 요구가 있습니다. 서로 다른 요구에 따라include는 서로 다른 파일, 예를 들어 사람마다 다른 설정을 하기 때문에 동적인include 파일을 요구합니다. 
코드는 다음과 같습니다.
 
 
  
Function include(filename) 
 Dim re,content,fso,f,aspStart,aspEnd 

 set fso=CreateObject("Scripting.FileSystemObject") 
 set f=fso.OpenTextFile(server.mappath(filename)) 
 content=f.ReadAll 
 f.close 
 set f=nothing 
 set fso=nothing 

 set re=new RegExp 
 re.pattern="^\s*=" 
 aspEnd=1 
 aspStart=inStr(aspEnd,content," do while aspStart>aspEnd+1  
  Response.write Mid(content,aspEnd,aspStart-aspEnd-2) 
  aspEnd=inStr(aspStart,content,"%\>")+2 
  Execute(re.replace(Mid(content,aspStart,aspEnd-aspStart-2),"Response.Write ")) 
  aspStart=inStr(aspEnd,content," loop 
 Response.write Mid(content,aspEnd)  
 set re=nothing 
End Function 

사용 예:
 
  
include("youinc.asp") 

좋은 웹페이지 즐겨찾기