如何在php变量中包含*.tpl文件



我想做的是通过电子邮件将excel文件作为从智能tpl文件创建的附件,所以目前我正在做的是:

    $smarty->display('export-report.tpl');
    $name=str_replace(" ","",$_POST['catname'])."_".date('d-m-Y');
    Header("Content-Type: application/vnd.ms-excel");
    Header("Content-Disposition: attachment; filename=".$name.".xls");

但我下一步想做的不是直接从浏览器下载excel文件,而是将其附加并发送到电子邮件中。为了做到这一点,我首先将文件保存在服务器上,并创建excel文件,我需要excel的内容(tpl文件中包含的html)位于php变量中。

所以我的问题是如何得到这个:

$smarty->display('export-report.tpl');

包含在这样的变量中:

$content

谢谢。

您需要这样使用fetch方法:

$content = $smarty->fetch('export-report.tpl');

编辑

也许你想要的只是以这种方式更改订单:

$name=str_replace(" ","",$_POST['catname'])."_".date('d-m-Y');
header("Content-Type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=".$name.".xls");
$smarty->display('export-report.tpl');

$content = $smarty->fetch('export-report.tpl');
$name=str_replace(" ","",$_POST['catname'])."_".date('d-m-Y');
header("Content-Type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=".$name.".xls");
echo $content;

最新更新