ASP生成静态模版技术(带参数的标签)

来源:风之相随BLOG 时间:2009-03-03 12:29:00 

 

<!--模板-->
<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
0
投稿

猜你喜欢

  • JS原型继承四步曲及原型继承图一览

    2024-06-13 14:56:04
  • Python 通过调用接口获取公交信息的实例

    2023-06-17 21:16:46
  • 对python读写文件去重、RE、set的使用详解

    2022-09-25 04:33:48
  • 解决使用python print打印函数返回值多一个None的问题

    2021-08-22 07:52:09
  • vue-simple-uploader上传成功之后的response获取代码

    2024-06-05 15:28:44
  • 通过实例解析Python调用json模块

    2022-09-22 02:05:06
  • linux服务器下PHPCMS v9 安全配置详解

    2023-11-17 11:51:52
  • python itertools包内置无限迭代器

    2023-11-16 18:58:59
  • MySQL5.7.18主从复制搭建(一主一从)教程详解

    2024-01-25 12:55:03
  • 教你如何在CI框架中使用 .htaccess 隐藏url中index.php

    2023-11-14 11:49:57
  • IronPython连接MySQL的方法步骤

    2024-01-27 05:43:05
  • 如何理解Python中包的引入

    2021-08-14 11:42:31
  • Jupyter Notebook运行代码无反应问题及解决方法

    2023-07-21 17:38:04
  • Python编写nmap扫描工具

    2021-08-07 14:53:10
  • 使用python实现离散时间傅里叶变换的方法

    2021-10-26 19:44:07
  • python爬虫之利用selenium+opencv识别滑动验证并模拟登陆知乎功能

    2023-10-17 22:33:37
  • 二种sql分页查询语句分享

    2024-01-15 10:29:04
  • openCV显著性检测的使用

    2022-10-20 12:25:02
  • PHP模板引擎Smarty的缓存使用总结

    2023-11-15 09:55:12
  • python实现邮件循环自动发件功能

    2021-01-20 02:39:24
  • asp之家 网络编程 m.aspxhome.com