Patch for (Re: Idle thoughts on dealing with the "multiple compiled template directory issue")

From: Date: Thu, 08 Mar 2001 22:43:18 +0000
Subject: Patch for (Re: Idle thoughts on dealing with the "multiple compiled template directory issue")
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-356@lists.php.net to get a copy of this message
Hi all, I needed this, so I wrote a patch that will allow you to assign a 'module name' to a smarty object. The idea is that you split up you templates in 'modules'; for example, one part for customer profile handling, one part for a forum, whatever. Or, you could use it like I do: you have one website, but with several frontends. Anyway, how it works: you set the module_name of your smarty object like $smarty->module_name = 'customer1'; You put your templates in a directory called 'customer1' in the smarty template directory. Now, smarty will automagically create the template cache in templates_c/customer1, and the cache in (for example) ./cache/customer1/d41d8cd98f00b204e9800998ecf8427e/d4/d41d8cd98f00b204e9800998ecf8427e_d41d8cd98f00b204e9800998ecf8427e.cache You can make a more complicated directory structure by using 'customer1/site3/specialcustomers' or so as the module name. You can also change the default value for $module_name in Smarty.class.php if you have a seperate copy of Smarty for every site you run this way, if you host them on different virtual hosts for example or even on seperate servers. If you don't want to use this feature, just set module_name to '' and smarty will behave exactly as it does now. The overhead caused by this is about 8 if() statements if you don't use the module_name feature, and a few string concats more if you do. If you think this is too much overhead or bloat or you think this will slow down your application noticeably, I suggest you invest some money in a new server or new provider :-) I have attached a tarball with diffs for Smarty.class.php and Smarty_Compiler.php, and the complete versions of these files for the people without access to the wonderfull 'patch' program. I would like to warn everyone that it is only tested a little bit, let me know if you find any problems. It should even be trivial to patch it yourself. cheers, roel On Wed, Mar 07, 2001 at 05:48:57PM -0500, clayton collie wrote: > as mentioned before in the list, there are folks like myself that for > various reasons need to have multiple template output/cache directories. a > thought that just crossed my mind is that you can hack around this > requirement by making the compiled template names reflect the directory > heirarchy. let me see if i can explain : > > Lets say i have two directories , both with an index.tpl > > admin/news/index.tpl (1) > public/news/index.tpl (2) > groups/news/index.tpl > > when generating the temp files, we can encode the dir structure into the > name of the generated script, so > (1) becomes something like admin@news@ab534jhj1kj3.php and > (2) becomes public@news@ab534jhj1kj3.php > > where "@" is a symbol which wond screw with the host OS's file naming > conventions. of course this requires the compiler to get the directory of > the script its parsing, but the overhead on that should be neglegible. > > clayton > > > > > > --- > You are currently subscribed to smarty as: roel@2e-systems.com > To unsubscribe send a blank email to $subst('Email.Unsub') > Visit Smarty's homepage at > http://www.phpinsider.com/php/code/Smarty/

Attachment: [application/x-gzip] module_support.Smarty.tar.gz
« previous php.smarty.general (#356) next »