<%
´========================================================= 【相关文章:.NET客户端应用程序:.NET应用程序】 【扩展阅读:创建可编辑的xml文档(之五)执行中的t】´ file: class_template.asp 【扩展信息:DirectShow中常见的RGB/YU】 ´ version:1.0 ´ date: 2004-5-7 ´ script written by r.h ´ description: asp template class ´========================================================= ´ copyright (c) 2004 interflower studios. all rights reserved. ´ web: http://www.interflower.cn ´ need help? contact: ranhuan@msn.com ´========================================================= ´========================================================= ´模板中替换的部分用{{%}}表示 ´模板中的循环用<!-- begin % -->开始 <!-- end % -->结束 支持一次嵌套 class template private tmp private tpl_dir, tpl, tpl_blk private var_list, blk_list, blk_var_list private re, match, matchs private sub class_initialize sql = "" tpl_dir = "templates/" tpl = "" blk="" set var_list = server.createobject("scripting.dictionary") set blk_list = server.createobject("scripting.dictionary") set blk_var_list = server.createobject("scripting.dictionary") set re = new regexp end sub ´取得主体模板 ´======================== ´从变量取出 public sub settpl(tplvar) tpl = tplvar end sub ´ 从db中取出,自己修改sql语句 public sub settpldb(tplname) dim sql, rs set rs = server.createobject("adodb.recordset") sql = "select content from templates where name = ´"&tplname&"´" rs.open sql,conn,1,1 if rs.recordcount <> 1 then response.write("数据库错误!<br>") response.end() end if tpl = rs("content") rs.close set rs = nothing end sub ´从文件取出 public sub settplfile(tplfile) dim fso, ofile set fso = server.createobject("scripting.filesystemobject") if fso.fileexists(server.mappath(tpl_dir & tplfile)) then set ofile = fso.opentextfile(server.mappath(tpl_dir & tplfile)) tpl = ofile.readall ofile.close set ofile = nothing else response.write "模板文件不存在!<br>" end if set fso = nothing end sub ´取得区块模板 ´======================== ´从变量取出 public sub setblk(blkname, tplvar) re.ignorecase = true re.global = true re.pattern = {{ & blkname & }} tpl = re.replace(tpl, tplvar) rs.close end sub ´从数据库取出 public sub setblkdb(blkname, tplname) dim sql, rs set rs = server.createobject("adodb.recordset") sql = "select * from templates where name = ´"&tplname&"´" rs.open sql,conn,1,1 tmp = rs("content") rs.close setblk blkname, tmp set rs = nothing end sub ´从文件取出 public sub setblkfile(blkname, tplfile) dim fso, ofile set fso = createobject("scripting.filesystemobject") if fso.fileexists(server.mappath(tpl_dir &tplfile)) then set ofile = fso.opentextfile(server.mappath(tpl_dir &tplfile)) tmp = ofile.readal setblock blkname, tmp ofile.close ... 下一页