简体   繁体   English

如何在多个站点上重复使用相同的Smarty模板?

[英]How to reuse same Smarty templates for multiple sites?

I'm maintaining a PHP code base that is shared between wiki websites. 我正在维护一个Wiki网站之间共享的PHP代码库。 What I mean is that there is a single directory /web/wiki with PHP scripts that serve several websites, like wiki-devs.domain.com , wiki-public.domain.com , etc. It was written this way because all wikis look the same, and fixing a bug (or adding a feature) in one of them automatically means that all of them get the same fix/feature. 我的意思是说,有一个包含PHP脚本的目录/web/wiki ,用于服务多个网站,例如wiki-devs.domain.comwiki-public.domain.com等。之所以这样写是因为所有Wiki看上去相同,并且自动修复其中的一个错误(或添加功能)意味着它们所有人都具有相同的修复/功能。 The PHP code uses $_SERVER['HTTP_HOST'] to change logo of the wiki and to select the right database, etc, but all the other code remains the same for all wikis. PHP代码使用$_SERVER['HTTP_HOST']更改Wiki的徽标并选择合适的数据库, $_SERVER['HTTP_HOST'] ,但是所有其他代码对于所有Wiki均保持不变。

I'm rewriting this web project to use Smarty templates, but I can't quite understand how to make Smarty avoid serving a template (let's say sidebar.template.html ) that was compiled for wiki-devs.domain.com to wiki-public.domain.com , as it doesn't know that there are multiple domains accessing the same code. 我正在重写此Web项目以使用Smarty模板,但是我不太了解如何使Smarty避免将为wiki-devs.domain.com编译为wiki-devs.domain.com的模板(例如sidebar.template.htmlwiki-public.domain.com ,因为它不知道有多个域访问同一代码。

I hope you understand what I mean. 我希望你明白我的意思。 Just to re-iterate: when "wiki-devs" accesses the site, Smarty generates template for "wiki-devs", but then if "wiki-public" accesses the site a second later, the same template will get served to them. 再次重申:当“ wiki-devs”访问该站点时,Smarty会为“ wiki-devs”生成模板,但是如果“ wiki-public”稍后再访问该站点,则将向他们提供相同的模板。

You should use the one directory for Smarty template and different compile directory for each site. 您应该为Smarty模板使用一个目录,为每个站点使用不同的编译目录。 This way you will avoid the problems with compilation. 这样,您将避免编译问题。

For example you can use something like that: 例如,您可以使用类似的方法:

    $sitename=$_SERVER['HTTP_HOST'];        
    $smarty->template_dir='themes/themename/';
    $smarty->compile_dir='files/compile/'.$sitename.'/';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM