【问题标题】:Smarty - Export txt files from TPLSmarty - 从 TPL 导出 txt 文件
【发布时间】:2014-09-23 09:01:23
【问题描述】:

我基本上有这个代码:

<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 smarty


【解决方案1】:

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

如果你希望很糟糕非常糟糕的事情,你可以使用{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

【讨论】:

    猜你喜欢
    • 2015-08-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-23
    • 1970-01-01
    • 2011-11-18
    • 1970-01-01
    相关资源
    最近更新 更多