Smarty-从TPL导出txt文件


Smarty - Export txt files from TPL

我基本上有这样的代码:

<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tr>
<td>{$root.page.contentgroup.Directory[0]}</td>
<td>{$root.page.contentgroup.Title[0]}</td>
<td>{$root.page.contentgroup.Description[0]}</td>
</tr>
</table>

我很想添加一个按钮,当我点击它时,它会生成3个txt文件。当脚本生成txt文件时,它应该根据{$root.page.contentgroup.Directory[0]}来定位它们。例如:

<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tr>
<td>mydirectory</td> {**directory.txt**}
<td>mytitle</td> {**title.txt**}
<td>mydescription</td> {**description.txt**}
</tr> 
</table>
[SUBMIT]

当我点击提交时,脚本会生成3个txt文件,并在上找到它们

mysite/folder/{$root.page.contentgroup.Directory[0]}/directory.txt
mysite/folder/{$root.page.contentgroup.Directory[0]}/title.txt
mysite/folder/{$root.page.contentgroup.Directory[0]}/description.txt

做这件事的更好方法是什么?我只能使用智能功能((

感谢

这必须用php实现。Smarty是一个模板引擎,必须仅用于演示(或者更好的-我的意见-根本不使用模板引擎。这里是一个基于意见的问题。)

如果您非常想让非常糟糕的事情,您可以使用{php}标记,该标记允许php代码嵌入smarty的.tpl文件中。

{php}
   // including a php script directly from the template.
   include('/path/to/your_file_generation_script.php');
{/php}

http://www.smarty.net/docsv2/en/language.function.php.tpl