一、display和fetch的区别
1、display调用的fetch方法,即:display() = echo fetch()
直接看源码,找到元凶:
$smarty->display('xx.html')
$smarty->fetch('xx.html')
echo $smarty->fetch('xx.html')
二、mini函数
1、mini模板类
function comp($file) {
$html = file_get_contents($file);
$html = str_replace('{$', '<?php echo $', $html);
$html = str_replace('}', ';?>', $html);
$compfile = $temp.'.php';
file_put_contents($compfile, $html);
return $compfile;
}
$sql = 'select ....';
$title = '这是标题';
include( comp('./xx.html') );
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<h1>{
$title}</h1>
</body>
</html>
2、最直接的修改:
class Mini{
function comp($file) {
$h = file_get_contents($file);
$h = str_replace('{$', '<?php echo $', $h);
$h = str_replace