简体   繁体   中英

How to reuse same Smarty templates for multiple sites?

I'm maintaining a PHP code base that is shared between wiki websites. 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. 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.

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.

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.

You should use the one directory for Smarty template and different compile directory for each site. 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.'/';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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