Re: [SMARTY-DEV] feature request

From: Date: Mon, 05 Jan 2004 14:49:22 +0000
Subject: Re: [SMARTY-DEV] feature request
References: 1  Groups: php.smarty.dev 
Request: Send a blank email to php-smarty-dev+get-2023@lists.php.net to get a copy of this message
Lazy loading variables can certainly have its performance issues, but there are times when this is useful. For example, if you want to get some information about an article, you could write a custom function: {get_article_info id=$art_id value="author"} This way if the template designer needs some information about the article (such as the author), they can get this at runtime. This may actually help performance since all the article data isn't needlessly assigned before hand on every page load. If you really feel the need to do this for every single template variable, there are ways you could do it, such as a custom function or object call like so: {getvar name="myvar" assign="myvar"} {$myobj->getvar name="myvar" assign="myvar"} You could then use a prefilter to transpose {$myvar} to one of the statements given above. Be sure to use template caching, and be sure getvar has it's own method of caching data. On Sun, 2004-01-04 at 11:41, Peter Billen wrote: > Hi all, > > I have a feature request. I'll explain what I'm thinking off: > > I want to give the template designers as much information as possible. But > assigning all the possible variables (with the assign() function) is > useless, because most of the times the template designer doesn't user all > the variables, so there may be unneeded database queries (for example) to > set all variables. > > Therefore, it might be a good idea only to retrieve the information when the > user asks for it. This can be detected when the template asks for a variable > {$var} that isn't set yet. > > So my request is: a function in class Smarty that will be called when the > template asks for a variable that isn't set yet (so I can override Smarty > and implement the function) OR a system similar as the plugins > (http://smarty.php.net/manual/en/plugins.php) so I can register my own > function as 'call when template asks for unknown variable'. > > Besides this, I don't know if this is a good method of programming: a > template may ask, for example, 'topic_name' and I detect that variable isn't > set yet => I get it from the database. But after this, the template asks for > 'topic_text' and I detect again that variable isn't set yet => I get it from > the database. But now I have 2 queries (for 'topic_name' and 'topic_text') > which could be combined into one query => overhead because in this situation > 2 queries will take more time than 1 query. > > An option might be to retrieve 'topic_text' also when the template asks for > 'topic_name', and cache/store it in memory. But what about the situation > when 'topic_text' is NOT called in the template => overhead because I > retrieved too much information, so the query takes more time than needed. > > Kind regards, > > Peter

« previous php.smarty.dev (#2023) next »