在實際工作中我們經常要使用到模版,這樣不僅保證了每頁的一致性,也減少了我們的工作量,本文介紹怎麼使用ASP讀取HTML模版的方法(附代碼)
模片頁面: m.htm
標題:{title}
內容:{content}
調用頁面xxx.ASP
My_moban=LoadFile(m.htm)
If My_moban <> then
My_moban=(replace(My_moban,{title},武林網
My_moban=(replace(My_moban,{content},http://www.vevb.com))
Response.Write My_moban
end if
Function LoadFile(m_Root)
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 response.write(模板文件& m_FileName & 不存在!) :response.end
set hndFile = fso.OpenTextFile(Filename)
if not hndFile.atendofstream then
LoadFile = hndFile.ReadAll
end if
Set hndFile = Nothing
Set fso = Nothing
If LoadFile = Then response.write(不能讀取模板文件& m_FileName & 或文件為空!):response.end
End Function
以上方法僅供參考,大家可以舉一反三。