tp.set_block "b" '设置区块,对应图中的 block b
for tmpc=1 to 10 '设置循环次数,可以根据程序而定
tp.set_bvar "t1","alax"&tmpc '解析区块中的变量
tp.set_bvar "t2","proa"&tmpc
tp.set_bvar "t3","hotsjf"&tmpc
tp.prase_block(10-tmpc) '把区块作为变量来看,解析整个区块
next
<%
'======================================'
' hotTemplate
' by hotsjf
' 2004.7.28
' sjf008@tom.com
' some rights reserved
'======================================'
On Error Resume Next
Class hotTemplate
'class member
dim file
dim var_key(50)
dim var_val(50)
dim var_num
dim bvar_key(50)
dim bvar_val(50)
dim bvar_num
dim block_name
dim block_content
dim new_block
dim debug
dim clear_unknown_tag
dim beginBlockStart
dim beginBlockEnd
dim endblockStart
dim endBlockEnd
dim varBegin
dim varEnd
'-------------------------------------------------------------------'
'初始化
Private Sub Class_Initialize
var_num=0
bvar_num=0
debug=false
beginBlockStart="<!-- begin block "
beginBlockEnd=" -->"
endblockStart="<!-- end block "
endBlockEnd=" -->"
varBegin="{"
varEnd="}"
file=""
clear_unknown_tag=true
if debug then
response.write ("in Class_Initialize() <br>")
end if
End Sub
'-------------------------------------------------------------------'
'加载模板文件
Public function loadfile(filename)
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile( server.mappath(filename),1)
if err.number>0 then
exp_msg("no file matched!")
end if
file = f.ReadAll
'write into cache
Application.Lock
Application("hot_tp"&filename)=file
Application.Unlock
if debug then
response.write ("in loadfile() ,filename:"&file&"<br>")
response.write ("in loadfile() ,cache:"&Application("hot_tp"&filename)&"<br>")
end if
f.close
set fso=nothing
End function
'-------------------------------------------------------------------'
'从缓存加载模板文件
public function loadfile_fromcache(filename)
if Application("hot_tp"&filename)="" then
loadfile(filename)
else
file = Application("hot_tp"&filename)
end if
end function
'-------------------------------------------------------------------'
'更新缓存
public function update_cache(filename)
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile( server.mappath(filename),1)
if err.number>0 then
exp_msg("no file matched!")
end if
file = f.ReadAll
'write into cache
Application.Lock
Application("hot_tp"&filename)=file
Application.Unlock
end function
'-------------------------------------------------------------------'
'设置全局模板变量
Public function set_var(name,val)
if isarray(name) and isarray(val) then
tmp=0
for each key in name
if key="" then exit for
var_key(var_num)=key
var_val(var_num)=val(tmp)
tmp=tmp+1
if debug then
response.write ("in set_var() ,varname=>"&var_key(var_num)&"||val=>"&var_val
(var_num)&"||<br>")
end if
var_num=var_num+1
next
else
var_key(var_num)=name
var_val(var_num)=val
if debug then
response.write ("in set_var() ,varname=>"&var_key(var_num)&"||val=>"&var_val
(var_num)&"||<br>")
end if
var_num=var_num+1
end if
if err.number>0 then
exp_msg("set var error")
end if
End function
'-------------------------------------------------------------------'
'设置块中模板变量
Public fun