使用模板实现ASP代码与页面分离(3)
"电子邮件:<a href='mailto:kacarton@sohu.com'>kacarton@sohu.com</a><br>")
End Sub
'检查目录是否存在
Public Function FolderExist(ByVal path)
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
FolderExist = fso.FolderExists(Server.MapPath(path))
Set fso = Nothing
End Function
'读取文件内容
Private Function LoadFile()
Dim Filename, fso, hndFile
Filename = m_Root
If Right(Filename, 1)<>"/" And Right(Filename, 1)<>"\" Then Filename = Filename & "/"
Filename = Server.MapPath(Filename & m_FileName)
Set fso = CreateObject("Scripting.FileSystemObject")
If Not fso.FileExists(Filename) Then ShowError("模板文件" & m_FileName & "不存在!")
set hndFile = fso.OpenTextFile(Filename)
LoadFile = hndFile.ReadAll
Set hndFile = Nothing
Set fso = Nothing
If LoadFile = "" Then ShowError("不能读取模板文件" & m_FileName & "或文件为空!")
End Function
'处理错误信息
Private Sub ShowError(ByVal msg)
m_LastError = msg
Response.Write "<font color=red style='font-size;14px'><b>模板错误:" & msg & "</b></font><br>"
If m_HaltOnErr Then Response.End
End Sub
'设置模板文件默认目录
'Ex: kktTemplate.set_root("/tmplate")
' kktTemplate.Root = "/tmplate"
' root = kktTemplate.get_root()
' root = kktTemplate.Root
'使用类似set_root这样的命名方法是为了兼容phplib,以下将不再重复说明
Public Sub set_root(ByVal Value)
If Not FolderExist(Value) Then ShowError(Value & "不是有效目录或目录不存在!")
m_Root = Value
End Sub
Public Function get_root()
get_root = m_Root
End Function
Public Property Let Root(ByVal Value)
set_root(Value)
End Property
Public Property Get Root()
Root = m_Root
End Property
'设置模板文件
'Ex: kktTemplate.set_file("hndTpl", "index.htm")
'本类不支持多模板文件,handle为兼容phplib而保留
Public Sub set_file(ByVal handle,ByVal filename)
m_FileName = filename
m_BlockList.Add Handle, LoadFile()
End Sub
Public Function get_file()
get_file = m_FileName
End Function
' Public Property Let File(handle, filename)
' set_file handle, filename
内容版权声明:除非注明,否则皆为本站原创文章。