使用模板实现ASP代码与页面分离(6)
kkt.parse "list", "AnimalList", true
next
kkt.parse "out", "hndKktTemp", false
kkt.p "out"
set kkt = nothing
%>
执行结果:
<html><title>ASP模板-块的演示</title><body>
<table cellspacing="2" border="1"><tr><td>下面的动物您喜欢哪一种</td></tr>
<tr><td><input type="radio" name="chk">小猪</td></tr>
<tr><td><input type="radio" name="chk">小狗</td></tr>
<tr><td><input type="radio" name="chk">小强</td></tr>
</table>
</body>
3)嵌套块演示
模板文件myTemple3.tpl:
<html><title>ASP模板-嵌套块演示</title>
<body><table width="400" border="1" bordercolor="#000000">
<tr><td><div align="center">{myname}测试</div></td></tr>
<tr><td>我的动植物园:</td> </tr>
<!-- BEGIN animalList -->
<tr><td>{animal}</td></tr>
<!-- BEGIN plantList -->
<tr><td> {plant}</td></tr>
<!-- END plantList -->
<!-- END animalList -->
</table>
</body>
</html>
ASP代码:
<!--#INCLUDE VIRTUAL="kktTemplate.inc.asp"-->
<%
dim my_color, kkt, myname, animal, plant
set kkt = new kktTemplate
myname = "kktTemplate block test..."
animal = array("动物", "植物")
plant = array(array("小猪","小白","小强"), array("玫瑰","向日葵"))
kkt.set_file "hndKktTemp", "myTemple3.tpl"
kkt.set_var "myname", myname, false
kkt.set_block "hndKktTemp", "animalList", "a"
kkt.set_block "animalList", "plantList", "p"
for i=0 to UBound(animal)
kkt.set_var "animal", animal(i), False
kkt.unset_var "p"
'kkt.set_var "p", "", false
for j=0 to UBound(plant(i))
kkt.set_var "plant", plant(i)(j), false
kkt.parse "p", "plantList", true
next
kkt.parse "a", "animalList", true
next
kkt.parse "out", "hndKktTemp", false
kkt.p "out"
%>
执行结果:
<html><title>ASP模板-嵌套块演示</title>
<body><table width="400" border="1" bordercolor="#000000">
<tr><td><div align="center">kktTemplate block test...测试</div></td></tr>
<tr><td>我的动植物园:</td> </tr>
内容版权声明:除非注明,否则皆为本站原创文章。