3.模板路径设置
图片会自动转换无须设置
test_2.htm
显示结果:<br>
<img border="0" src="images/banner_3.gif" width="590" height="80">
test_2.php
<?
include("./template.php");
$tl = new template();
$tl->set_file('test_2');
$tl->p();
?>
4.模板条件判断
test_3.htm
<!-- IF[$a==1] -->
变量a为{a}
<!-- ELSE -->
变量a为空
<!-- END -->
<!-- IF[$a==$b] -->
变量a等于变量b
<!-- ELSEIF[$a>$b] -->
变量a大于变量b
<!-- ELSE -->
变量a小于变量b
<!-- END -->
test_3.php
<?
include("./template.php");
$tl = new template();
$a = 1;
$b = 2;
$tl->set_file('test_3');
$tl->p();
?>
5.循环处理方式
注释说明
此效果将数组信息快速处理显示,用法跟foreach()一样。
test_4.htm
<!-- $user_list AS $user -->
账号:{user['name']}<br>
密码:{user['pass']}<br><br>
<!-- END -->
test_4.php
<?
include("./template.php");
$tl = new template();
$user_list = array(
array(
'name' => 'md-chinese',
'pass' => '654321',
),
array(
'name' => 'test',
'pass' => '123456',
)
);
$tl->set_file('test_4');
$tl->p();
?>
嵌套循环方式:
test_5_1.htm
<table border="1" width="300" bordercolor="#C0C0C0">
<!-- $cate AS $ck=>$cv -->
<tr>
<td><b>{cv}</b></td>
</tr>
<!-- $subcate[$ck] AS $K=>$V -->
<tr>
<td> ->{V}</td>
</tr>
<!-- END -->
<!-- END -->
test_5_1.php
<?
include("./template.php");
$tl = new template();
$cate = array('分类1','分类2','分类3');
$subcate = array(array('计算机','报纸','杂志','鼠标'),array('青菜','白菜'),array('橘子','香蕉','苹果'));
$tl->set_file('test_5_1');
$tl->p();
?>