高端网站建设-浅谈 ASP 模板技术之参数传递
author:一佰互联 2019-04-15   click:186
 如果我告诉你,他们都是一个程序,只是由相关的站长,设计不同的模板得到的页面显示,你就会发现,这个系统的优良性。

 

当然由于这套系统的高端性,目前普通用户无法使用,于是我开发了我自己的内容管理系统 kiss 内容管理系统。

 

而要给用户一个模板系统,首先,就是要有一个简单易懂的标记系统。大家看看下面的代码,看是否容易理解:

<tag:loop channelid="1" pagesize="10" title="20" type="NEW" column="1">

 

略有HTML经验的人,就知道,这是一个模板标记里的循环标记,因为这是最常用的,你看我们网站的首页,列出10条文档也就只需要写一个这样的标记就完成了,这是不是让不明白编程的人,也很容易做出自己设计的页面出来呢?

 

参数说明:

channelid 为一个栏目的在数据库中的ID

pagesize 为列举多少个文档

title 为标题的长度

type 为列表列型,这里的”NEW”我们设定为最新的文档

column 为显示几列

 

以上介绍是给不会编程,或者对不了解内容系统的人做个普及,并且给我的内容管理系统打个广告,而且我想说的是,蓝色理想站点用的内容管理系统模板模块,要比我的强大很多。

 

下面轮到程序员了,其它人可以不用往下看。

那么怎么把它们的值读出来呢?

下面这个函数是最后的,用来解析所有模板的内容

 

复制代码 代码如下:

 

"【功能】自定义模板标签

Function ProcessCustomTags(ByVal sContent)

Dim objRegEx, Match, Matches

"建立正则表达式

Set objRegEx = New RegExp

"查找内容

objRegEx.Pattern = "<tag:.*/>"

"忽略大小写

objRegEx.IgnoreCase = True

"全局查找

objRegEx.Global = True

"Run the search against the content string we"ve been passed

Set Matches = objRegEx.Execute(sContent)

"循环已发现的匹配

For Each Match in Matches

"Replace each match with the appropriate HTML from our ParseTag function

sContent = Replace(sContent, Match.Value, ParseTag(Match.Value))

Next

"消毁对象

set Matches = nothing

set objRegEx = nothing

"返回值

ProcessCustomTags = sContent

End Function

 

  在上面的代码中,用到了正则表达式,如果你对它还不是很了解,请参阅相关资料,这里就不详细介绍了。

 

那么怎么取出参数值呢,也是一个函数:代码拷贝框 

 

复制代码 代码如下:

 

"【功能】取得模板标签的参数名

"如:<tag:loop channelid="1" pagesize="10" title="20" type="NEW" column="1">

function GetAttribute(ByVal strAttribute, ByVal strTag)

Dim objRegEx, Matches

"建立正则表达式

Set objRegEx = New RegExp

"查找内容 (the attribute name followed by double quotes etc) 

objRegEx.Pattern = lCase(strAttribute) & "=""[0-9a-zA-Z]*"""

"忽略大小写

objRegEx.IgnoreCase = True

"全局查找

objRegEx.Global = True

"执行搜索

Set Matches = objRegEx.Execute(strTag)

"如有匹配的则返回值, 不然返回空值

if Matches.Count > 0 then

GetAttribute = Split(Matches(0).Value,"""")(1)

else

GetAttribute = ""

end if

"消毁对象

set Matches = nothing

set objRegEx = nothing

end function

OK好了,那怎么解析像上面<tagloop:>内容呢?

下面就是一个函数:

 

复制代码 代码如下:

 

"【功能】解析并替换相应的模板标签内容

function ParseTag(ByVal strTag)

dim arrResult, ClassName, arrAttributes, sTemp, i, objClass

"如果标签是空的则退出函数

if len(strTag) = 0 then exit function

"Split the match on the colon character (:)

arrResult = Split(strTag, ":")

"Split the second item of the resulting array on the space character, to

"retrieve the name of the class

ClassName = Split(arrResult(1), " ")(0)

"Use a select case statement to work out which class we"re dealing with

"and therefore which properties to populate etc

select case uCase(ClassName)

"It"s a loop class, so instantiate one and get it"s properties

case "LOOP" 

set objClass = new LOOP_Class

LOOP.Channelid= GetAttribute("channelid", strTag")

LOOP.Pagesize= GetAttribute("pagesize", strTag")

LOOP.title = GetAttribute("title", strTag")

LOOP.type = GetAttribute("Type", strTag")

ParseTag = LOOP.column (GetAttribute("column", strTag"), true)

"Destroy our class object

set objClass = nothing

end select

end function

 

高端网站建设价格套餐:

500元成品模板网站套餐1000元基础型网站套餐1800元标准定制设计套餐2800元精美定制设计套餐3800-8000元商务型套餐行业门户型套餐其它定制套餐 文章由重庆一佰互联高端网站建设http://www.yinxi.net编辑整理,转载请注明出处