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

Posted on 2005-08-18 12:13  e动力  阅读(528)  评论(0)    收藏  举报

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

--------------------------------------------------------------------------------
 
日期:2005-6-16 8:36:45 来源:来自网络 查看:[大 中 小] 作者:不详 热度:5
'/////////////////////////////////////////////////////
'通过模板生成静态页面示例
'作者: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
%>
 

博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3