我正在制作一个PHP维基引擎,所有指向它的网站都使用相同的模板。然而,一些网站有一个自定义的模板。如果这个自定义模板存在,我可以让Smarty使用它吗?
下面是我的目录结构:
/web/wiki/templates <-- all templates here
/web/wiki/templates/wiki.domain.com <-- individual template如何让smarty首先在wiki.domain.com中使用/web/wiki/templates/wiki.domain.com中的模板,如果该目录中不存在该模板,则在/web/wiki/templates中使用该模板
我可以为Smarty定义多个模板目录,并让它先尝试从顶层目录中选择模板吗?如果我可以这样做,我可以简单地更改模板目录的顺序:
/web/wiki/templates/wiki.domain.com
/web/wiki/templates 发布于 2012-06-17 16:20:23
default_template_handler是一个在找不到模板时调用的回调函数。在unit test中可以找到一些“示例”
发布于 2014-01-30 22:52:40
在Smarty Docs中,尝试:
// set multiple directoríes where templates are stored
$smarty->setTemplateDir(array(
'one' => './templates',
'two' => './templates_2',
'three' => './templates_3',
));发布于 2012-06-17 07:21:31
我不认为你可以在不同的模板上设置优先级,但我不确定。您可以做的是检查特定的模板是否存在:
// check for if a special template exists
$template = 'default.tpl.php';
if ($smarty->template_exists('example.tpl.php')) {
$template = 'example.tpl.php';
}
// render the template
$smarty->display($template);https://stackoverflow.com/questions/11067774
复制相似问题