Php Smarty动态模板包括
有没有办法动态设置要包含的文件?当我尝试时,会收到一条错误消息(见下文)。例如,以该模板为例: /templates/main.tplPhp Smarty动态模板包括,php,smarty,Php,Smarty,有没有办法动态设置要包含的文件?当我尝试时,会收到一条错误消息(见下文)。例如,以该模板为例: /templates/main.tpl <!DOCTYPE html> <html> <head> <title>My Title</title> </head> <body> {include file='$file'} </body> &l
<!DOCTYPE html>
<html>
<head>
<title>My Title</title>
</head>
<body>
{include file='$file'}
</body>
</html>
我的头衔
{include file='$file'}
下面是PHP代码:
<?php
switch($page){
case "page1":
$file = "/templates/page1.tpl";
break;
case "page2":
$file = "/templates/page2.tpl";
break;
case "page3":
$file = "/templates/page3.tpl";
break;
}
$smarty->assign("file", $file);
$smarty->display("/templates/main.tpl");
好吧,我想出来了
Smarty不喜欢变量周围的引号
所以,{include file='$file'}
变成了{include file=$file}
好吧,我想出来了
Smarty不喜欢变量周围的引号
因此,{include file='$file'}
变成了{include file=$file}