Re: Other directories and Smarty

From: Date: Thu, 22 Feb 2001 19:24:20 +0000
Subject: Re: Other directories and Smarty
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-196@lists.php.net to get a copy of this message
Hello Monte, Thursday, February 22, 2001, 6:11:18 PM, you wrote: MO> Hi Adrian, MO> I've done a bit of brainstorming on this issue. If I missed anything or MO> misunderstood what your needs are, let me know :-) First of all, lets MO> look at a method of doing this with no modifications to Smarty: MO> An overview of how Smarty works: MO> * Smarty traverses the entire template directory MO> * If any templates need compiling, Smarty compiles them and puts MO> the results into the templates_c directory with the same MO> directory structure. MO> * Smarty executes the application MO> If we try to add new template directories to Smarty, then Smarty must MO> figure out what needs to be compiled and where to put them all without MO> conflicts. Remember there is only one directory that compiled templates MO> are placed, we don't want to introduce name-space conflicts. MO> We can devise a method to manage our directory structures in a way that MO> Smarty understands, using symbolic links. MO> For example, let's say we have applications that all share common MO> templates. What you would want to do is put your common templates in a MO> directory by themselves. MO> common templates MO> ---------------- MO> /export/smarty/templates/common/ MO> /export/smarty/templates/common/header.tpl MO> /export/smarty/templates/common/footer.tpl MO> application templates MO> --------------------- MO> /export/httpd/www.mysite.com/templates/ MO> So we have our template directory, but we want to be able to access our MO> common templates as well. We accomplish this by symlinking the common MO> template directory into our application template directory. MO> /export/httpd/www.mysite.com/templates/common -> MO> /export/smarty/templates/common/ MO> This way, Smarty "sees" the common templates as a subdirectory in the MO> application template directory, and can then traverse and compile the MO> common templates without interference with the application templates. MO> Now in your application template, include the common templates like so: MO> {include file="common/header.tpl"} MO> This also makes things clear in your template which includes are MO> application templates, and which are common templates. If you have more MO> than one source of common templates, add more symlinks. Personally I do not like this idea as: 1) It's a headache to install the application as I must remember to set all symlinks (and this is not beautifull solution :) 2) It won't work under windows (I do not care much though) MO> And now, another idea: MO> method that involves changing smarty MO> ------------------------------------ MO> We could change Smarty so that the $template_dir can take an associative MO> array of values, like so: MO> $template_dir = array("/path/to/common/templates/" => "common", MO> "/path/to/application/templates/" => "app"); MO> Then to include templates, you must include them like so: MO> {include file="common/header.tpl"} MO> {include file="app/body.tpl"} MO> Smarty would then traverse all templates in every directory to compile MO> them, and all templates would be in a subdirectory of the template MO> directory, and must be called as such from the template. At first glance MO> this looks doable, but may not be an easy change :-) Yes, that would be just a great! Especially in my case when I have many directories with application templates and one (maybe more in the future) shared directory with templates. MO> other ideas? Maybe you could change 'include' statement next way: if directory is specified {include file="path/to/shared/templates/template.tpl"} then first compile that template and include it from that path. If dir is not specified then behave like it is now. MO> Monte -- Best regards, Sergey mailto:esv@37.ru

« previous php.smarty.general (#196) next »