【发布时间】:2010-11-21 16:32:18
【问题描述】:
在 PHP 模板方面需要您的帮助。我是 PHP 新手(我来自 Perl+Embperl)。无论如何,我的问题很简单:
- 我有一个小模板来呈现一些项目,让它成为一篇博文。
- 我知道使用此模板的唯一方法是使用“包含”指令。
- 我想在遍历所有相关博客文章的循环中调用此模板。
- 问题:我需要向这个模板传递一个参数;在这种情况下,引用表示博客文章的数组。
代码如下所示:
$rows = execute("select * from blogs where date='$date' order by date DESC");
foreach ($rows as $row){
print render("/templates/blog_entry.php", $row);
}
function render($template, $param){
ob_start();
include($template);//How to pass $param to it? It needs that $row to render blog entry!
$ret = ob_get_contents();
ob_end_clean();
return $ret;
}
任何想法如何做到这一点?我真的很难过 :) 还有其他方法可以渲染模板吗?
【问题讨论】:
标签: php templates parameters include