|
|
|
|
你现在的位置:您现在的位置是: 中国ASP>>ASP教程>>fso组件 |
|
| asp静态模版技术之标签参数 |
|
<table width="100%" border="0" cellspacing="5" cellpadding="0"> <tr> <td><tag:article_list class_id="314" PageSize="4" Len="8" showtime="0" /></td> </tr> </table>
<% Call loadtemplate("test.htm") "============================== ""替换模板内容 "============================== Function loadtemplate(FileName) Dim TempHtml TempHtml = readfromfile(FileName) """处理用户标签 TempHtml = process_customtags(TempHtml) loadtemplate = TempHtml End Function
"============================== "【功能】解析并替换相应的模板标签内容 "============================== Function Parsetag(ByVal strtag) Dim arrResult, className, arrAttributes, sTemp, i, objclass "如果标签是空的则退出函数 If Len(strtag) = 0 Then Exit Function arrResult = MySplit(strtag, ":") className = MySplit(arrResult(1), " ")(0) Parsetag = strtag Dim nclass_id, nLen, nIsWhat, nshowtime select Case LCase(className) Case "article_list" nclass_id = 0 nLen = 24 nPageSize = 10 nshowtime = 0 If Not IsBlank(GetAttribute("pagesize", strtag)) Then nPageSize = GetAttribute("pagesize", strtag) If Not IsBlank(GetAttribute("class_id", strtag)) Then nclass_id = GetAttribute("class_id", strtag) If Not IsBlank(GetAttribute("Len", strtag)) Then nLen = Int(GetAttribute("Len", strtag)) If Not IsBlank(GetAttribute("showtime", strtag)) Then nshowtime = Int(GetAttribute("showtime", strtag)) Parsetag = show_article_list(nclass_id, nPageSize, nLen, nshowtime) End select End Function
"============================== "【功能】处理自定义标签 "============================== Function process_customtags(ByVal sContent) Dim objRegEx, Match, Matches "建立正则表达式 Set objRegEx = New RegExp "查找内容 objRegEx.Pattern = "<tag:[^<>]+?\/>" "忽略大小写 objRegEx.IgnoreCase = True "全局查找 objRegEx.Global = True Set Matches = objRegEx.Execute(sContent) "循环已发现的匹配 For Each Match in Matches sContent = Replace(sContent, Match.Value, Parsetag(Match.Value)) Next "消毁对象 Set Matches = Nothing Set objRegEx = Nothing "返回值 process_customtags = sContent End Function
"============================== "文件内容读取. "============================== Function readfromfile(ByVal File) Dim objStream On Error Resume Next Set objStream = Server.createObject("ADODB.Stream") If Err.Number = -2147221005 Then Response.Write "<div align="center">非常遗憾,您的主机不支持ADODB.Stream,不能使用本程序</div>" Err.Clear Response.End End If With objStream .Type = 2 .Mode = 3 .Open .LoadFromFile Server.MapPath(File) If Err.Number<>0 Then Response.Write "<div align="center">文件<font color="#ff0000">" & File & "</font>无法被打开,请检查是否存在!</font></div>" Err.Clear Response.End End If .Charset = "GB2312" .Position = 2 read1file = .ReadText .Close End With Set objStream = Nothing End Function
"============================== ""显示文章内容 "============================== Function show_article_list(class_id, nPageSize, nLen, nshowtime) 每人代码都不一样,自己写哈 End Function
"============================== "判断是否为空 "============================== Function IsBlank(ByRef TempVar) IsBlank = False select Case VarType(TempVar) "Empty & Null Case 0, 1 IsBlank = True "String Case 8 If Len(TempVar) = 0 Then IsBlank = True End If "Object Case 9 Dim tmpType tmpType = TypeName(TempVar) If (tmpType = "Nothing") or (tmpType = "Empty") Then IsBlank = True End If "Array Case 8192, 8204, 8209 If UBound(TempVar) = -1 Then IsBlank = True End If End select End Function %>
相关标签:asp静态模版 标签参数
|
|
|