[prev in list] [next in list] [prev in thread] [next in thread] 

List:       smarty-dev
Subject:    Re: [SMARTY-DEV] How to modify the Smartytemplate loding policy
From:       Rob Ellis <rob () web ! ca>
Date:       2003-03-25 16:34:30
[Download RAW message or body]

On Tue, Mar 25, 2003 at 04:22:45PM +0100, messju mohr wrote:
> On Tue, Mar 25, 2003 at 11:32:37AM -0300, luis wrote:
> > Messju,
> > I was looking for a "neat" way to do what I needed, that after all, is
> > not that weird. That's why I didn't dive into the code :-)
> > Do you think that an extra if statement can be a serious performance
> > problem in _smarty_include?
> 
> i thought of traversing a search-path for the template.  you have to
> do a stat() call (aka file_exists()) for each segment in your path,
> until the template in question is found. you have to do this for every
> template that is included. i think this can become a
> performance-problem.  i think this may even be the reason, why smarty
> does not support multiple template directories natively.
> 
> but give it a try and if it get's your job done it good. one (in this
> case me) shouldn't try to optimize in the design-phase anyway :)

i agree a template include path is a good idea -- it would be great
for setting up default templates for all kinds of things.
the file_exists checks can't be too much overhead ? (php 'include' 
also does this kind of search).

maybe it could be implemented in smarty by making template_dir
optionally an array? if is_array... search the array of directories...

note that currently (? or in older versions of smarty ?) you have to 
watch if you change template_dir to access a template with the same name,
e.g. this doesn't work:

   foreach ($search_dirs as $dir)
     if (file_exists($dir . DIRECTORY_SEPARATOR . $tpl_name)) 
         $smarty->template_dir = $dir;
   // ...
   $smarty->display($tpl_name);

with the default compile id, templates with the same relative 
path/name clobber each other.

- rob

> 
> 
>  
> > Luis
> > 
> > -----Original Message-----
> > From: messju mohr [mailto:messju@lammfellpuschen.de] 
> > Sent: Tuesday, March 25, 2003 11:06 AM
> > To: luis
> > Cc: 'Smarty-Dev'
> > Subject: Re: [SMARTY-DEV] How to modify the Smartytemplate loding policy
> > 
> > On Tue, Mar 25, 2003 at 10:44:55AM -0300, luis wrote:
> > > Why would I change {include} ? The application will then be hard to
> > > maintain because it's logical to use {include} to do {includes} In
> > some
> > > point {include} must share some code with {fetch} to get a template
> > from
> > > the source. I just want to know where is that intersecting code to
> > > change it and load templates from one dir or another.
> > 
> > look in the compiled template what is generated when you have
> > {include} in your template. you'll see that $this->_smarty_include()
> > is called.
> > 
> > both, fetch() and _smarty_include() use _get_compile_path() to retrieve
> > the path to the template. this is the intersecting part of them.
> > (you could have figured this out easily, if you had a look at the
> > source)
> > 
> > but you won't be happy in overruling _get_compile_path() to search a
> > path of template-directories, since _get_compile_path() is also used
> > to retrieve the compile-path of a template to *write* after compiling.
> > this can have funny effects.
> > 
> > you should better override _smarty_include() instead. but i'm sure it
> > will be a significant performance-hit to your compiled templates (if
> > no caching is in use).
> > 
> > > -----Original Message-----
> > > From: Jimmy Harlindong [mailto:jimmy@harlindong.com] 
> > > Sent: Tuesday, March 25, 2003 10:13 AM
> > > To: Smarty-Dev
> > > Subject: Re: [SMARTY-DEV] How to modify the Smartytemplate loding
> > policy
> > > 
> > > How about using a custom function? 
> > > 
> > > {insert}
> > > 
> > > or define a custom tag.
> > > 
> > > ----- Original Message ----- 
> > > From: "luis" <luis@fuegolabs.com>
> > > To: "'luis'" <luis@fuegolabs.com>; "'Jason Sweat'"
> > > <sweatjejm@mchsi.com>; <aztek@box.sk>
> > > Cc: "'Smarty Dev'" <smarty-dev@lists.php.net>
> > > Sent: Tuesday, March 25, 2003 10:19 PM
> > > Subject: [SMARTY-DEV] How to modify the Smartytemplate loding policy
> > > 
> > > 
> > > > Well, I can answer myself, no.
> > > > If I have 
> > > > display('foo.tpl');
> > > > and foo.tpl {includes file='header.tpl'}
> > > > I need to look BOTH for foo.tpl and header.tpl in templates/$user
> > and
> > > if
> > > > they are not found there in templates/
> > > > If I redefine fetch then foo.tpl can be checked but fetch is not
> > > called
> > > > for the included header.tpl template.
> > > > Ideas?
> > > 
> > > 
> > > 
> > > -- 
> > > Smarty Development Mailing List (http://smarty.php.net/)
> > > To unsubscribe, visit: http://www.php.net/unsub.php
> > > 
> > > 
> > > -- 
> > > Smarty Development Mailing List (http://smarty.php.net/)
> > > To unsubscribe, visit: http://www.php.net/unsub.php
> > 
> > -- 
> > E-Commerce: Verkauft etwas, das mit elektrischem Strom funktioniert.
> > (modern 
> > für Multimedia)
> >                                                              Andreas
> > Krennmair
> > 
> > -- 
> > Smarty Development Mailing List (http://smarty.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> 
> -- 
> E-Commerce: Verkauft etwas, das mit elektrischem Strom funktioniert. (modern 
> für Multimedia)
>                                                              Andreas Krennmair
> 
> -- 
> Smarty Development Mailing List (http://smarty.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 

-- 
Smarty Development Mailing List (http://smarty.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic