- 论坛徽章:
- 0
|
SmartTemplate 模板的嵌套问题。
主模板: page.htm
<html>
<head>
<title>{page_title}</title>
</head>
<body>
<h1>Page Header Bar.</h1>
<hr>
{body_text}
<hr>
<h2>Page Footer.</h2>
要填充的模板: box.htm
<p> This is a content box. <br>Content: {box_text}</p>
PHP CODE: box.php
<?php
$tpls = new SmartTemplate('box.htm');
$tpls->assign('box_text','This is a Test Text!');
$body_text = $tpls->result();
?>
PHP CODE: test.php
<?php
include_once('config.inc.php'); //模板全局参数设置脚本。
include_once('class.smarttemplate.php'); //模板类文件
$tpl = new SmartTemplate('page.htm');
$body_text = '';
include_once('box.php');
$tpl->assign('page_title','Text Page Test!');
$tpl->assign('body', $body_text);
$tpl->output();
?>
结果发现box.php文件无法解析模板中的{text}变量。
test.php文件无法解析{page_title}和{body_text}变量。
大概看了一下class.smarttemplate.php文件。
smarttemplate 的 result()方法是把缓冲区的内容取出来。
按理来说 $tpl 和 $tpls 两个对象的数据在不同的内存空间。
$tpls->result()把缓冲区的内容清空后怎么能影响$tpl对象呢?
另外很不理解 smarttemplate 的 output() 方法中的 $_top 参数。
而且还用了 global 声明。
smarttemplate 的模板文件仅仅限制于一个模板文件?
能不能实现PHPLIB中的template 的 set_file() 那样的功能?
一个模板对象能处理多个模板文件。而且可以自由的方便的对其中的某个模板文件的内容
嵌套到其他模板文件的某个变量中呢?
有没有类似 PHPLIB template 用法的模板,还带有模板控制功能的 IF ELSEIF 等之类的PHP模板?
谢谢!
[ 本帖最后由 inu 于 2007-1-12 10:37 编辑 ] |
|