Ease Template 变量各种用法
Ease Template 变量用法
Ease Template 在htm中定义模板变量都为变量名加大括号例如:{test} ,变量也可以使用数组形式{user[‘name’]}或对象形式{user->name}。
在class与function中使用et赋值的时候需要指定变量,设置方法为:
$tpl->set_var('user',$user[name]);
Ease Template 就是为了方便开发,数组、变量、对象都可以传入htm模板,您如果要赋值一个变量组可以用下面方法。
$set_array = array(1=>'FoundPHP',2=>'Ease',3=>'Template');
$tpl->set_var(
array(
'test' => '测试代码',
'more' => $set_array
)
);
为了您能够更深入了解,下面提供方便使用的测试代码:
test_1.php
<?php
include "template/ease_template.php";
$tpl = new FoundPHP_template();
//方法内使用指定变量
function test(){
global $tpl;
$more = array(1=>'SYSTN',2=>'Ease',3=>'Template');
$tpl->set_var(
array(
'test'=>'测试代码',
'more'=>$more
)
);
}
//常规变量
$color = '红色';
//调用方法
test();
$tpl->set_file('test_1');
$tpl->p();
?>
view/test_1.htm
<font color=red>这是一个{color}的{test}</font>
<!-- $more AS $v -->
{v}
<!-- END -->
本次演示的方法中提供了一个数组赋值到htm模板中进行循环显示操作。你现在可能还不明白循环的用法,没关系,请继续看下面的文章,将为你讲述更快捷、便利甚至是更个性的循环方式。