我想改变我的网站主页,使用php代码,我找到了我需要修改的tpl文件,问题是我没有使用tpl的经验,我想用php写它,但它不起作用。我正在尝试使用:
{include_php file="/path/to/somefile.php"}使用php语言,但它不工作。如何使用php语言在Smarty模板中使用tpl。
发布于 2015-12-13 06:22:18
我的建议是以下是一个php文件
include_once("/var/www/html/smarty/libs/Smarty.class.php");
$smartyobject=new Smarty();
$varr="stackoverflow"; //php variable it can also be a array";
$smartyobject->assign("website", $varr); //assigning a variable to "website", and this is now a smarty variable.
$smartyobject->display("tplfile"); //this is the actuall file that get displayed, in this tpl file you can use "website" variable {$website} smarty有很多in函数循环..所以不需要包含任何php文件。在php文件中做任何您想做的事情,将结果保存在一个变量中,并在tpl文件中显示它。
https://stackoverflow.com/questions/34245620
复制相似问题