您的位置:首页 > Web前端 > HTML

通过模板生成静态页面示例

2004-12-24 14:38 281 查看
'/////////////////////////////////////////////////////
'通过模板生成静态页面示例
'作者:griefforyou
'/////////////////////////////////////////////////////

<!--模块文件(template.htm)-->
<html>
<head>
<title>%TITLE%</title>
</head>
<body>
%CONTENT%
</body>
</html>

<!--TestTemplate.asp-->
<%
Dim fso,f
Dim strTitle,strContent,strOut
'创建文件系统对象
Set fso=Server.CreateObject("Scripting.FileSystemObject")

'打开网页模板文件,读取模板内容
Set f=fso.OpenTextFile(Server.MapPath("Template.htm"))
strOut=f.ReadAll
f.close

strTitle="这是生成的网页标题"
strContent="这是生成的网页内容"

'用真实内容替换模板中的标记
strOut=Replace(strOut,"%TITLE%",strTitle)
strOut=Replace(strOut,"%CONTENT%",strContent)

'创建要生成的静态页
Set f=fso.CreateTextFile(Server.MapPath("New.htm"),true)

'写入网页内容
f.WriteLine strOut
f.close

Response.Write "生成静态页成功!"

'释放文件系统对象
set f=Nothing
set fso=Nothing
%>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  html