在实际工作中我们经常要使用到模版,这样不仅保证了每页的一致性,也减少了我们的工作量,本文介绍怎么使用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
以上方法仅供参考,大家可以举一反三。