首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >是否可以让Smarty根据优先级从目录中选择模板?

问是否可以让Smarty根据优先级从目录中选择模板?
EN

Stack Overflow用户
提问于 2012-06-17 07:13:17
回答 4查看 629关注 0票数 4

我正在制作一个PHP维基引擎,所有指向它的网站都使用相同的模板。然而,一些网站有一个自定义的模板。如果这个自定义模板存在,我可以让Smarty使用它吗?

下面是我的目录结构:

代码语言:javascript
复制
/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定义多个模板目录,并让它先尝试从顶层目录中选择模板吗?如果我可以这样做,我可以简单地更改模板目录的顺序:

代码语言:javascript
复制
/web/wiki/templates/wiki.domain.com
/web/wiki/templates                
EN

回答 4

Stack Overflow用户

发布于 2012-06-17 16:20:23

default_template_handler是一个在找不到模板时调用的回调函数。在unit test中可以找到一些“示例”

票数 1
EN

Stack Overflow用户

发布于 2014-01-30 22:52:40

在Smarty Docs中,尝试:

代码语言:javascript
复制
// set multiple directoríes where templates are stored
$smarty->setTemplateDir(array(
    'one'   => './templates',
    'two'   => './templates_2',
    'three' => './templates_3',
));
票数 1
EN

Stack Overflow用户

发布于 2012-06-17 07:21:31

我不认为你可以在不同的模板上设置优先级,但我不确定。您可以做的是检查特定的模板是否存在:

代码语言:javascript
复制
// 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);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11067774

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档