运用模板生成静态页例

作者在 2006-07-06 03:31:00 发布以下内容

生成代码:

<%
fname="template.htm"
dim replaceweb(2)
replaceweb(0)="haha"
replaceweb(1)="模版生成静态页面"       '设置生成内容,实际中可从数据库读取
replaceweb(2)="模版生成静态页面实例"
set fso=server.createobject("scripting.filesystemobject")
set file=fso.opentextfile(server.mappath(fname),1,True)
FSOFileRead = file.ReadAll
set file=nothing
for i=0 to 2
 FSOFileRead=Replace(FSOFileRead,"$HTMLWEB["&i&"]",replaceweb(i))
next
Set outfile = fso.CreateTextFile(Server.Mappath("index.htm"))
outfile.Write FSOFileRead
outfile.close
Set outfile=nothing
Set fso=nothing
%>

模板:template.htm

<html>
<head>
<title>$HTMLWEB[0]</title>
</head>
<body>
<center>
<h1>$HTMLWEB[1]</h1><hr>
$HTMLWEB[2]
</center>
</body>
</html>

 

默认分类 | 阅读 2795 次
文章评论,共0条
游客请输入验证码
浏览33914次