我需要从php文件到.tpl文件显示一些外部数据.为此,我想将php文件包含到.tpl文件中.我试过以下代码来显示php文件内容到tpl.
{php} include('custom_code.php'); {/php}
Run Code Online (Sandbox Code Playgroud)
但在页面输出是 include('custom_code.php');
{php}已被弃用。查看使用插件扩展 Smarty。
将以下内容放入\xe2\x80\xa6/plugins/function.yourplugin.php:
<?php\nfunction smarty_function_yourplugin(array $params, Smarty_Template_Instance) {\n include \'your_other_file.php\';\n}\nRun Code Online (Sandbox Code Playgroud)\n\n并在您的模板中使用:
\n\n{yourplugin}\nRun Code Online (Sandbox Code Playgroud)\n