RE: [SMARTY-DEV] feature request

From: Date: Mon, 05 Jan 2004 16:45:29 +0000
Subject: RE: [SMARTY-DEV] feature request
References: 1  Groups: php.smarty.dev 
Request: Send a blank email to php-smarty-dev+get-2025@lists.php.net to get a copy of this message
Indeed, that's my purpose: load on demand, at runtime. Although there are some big issues: - the code is more difficult to change/update at a later date: sometimes, it may be difficult to avoid redundant calls (to the database for example), because some of the calls could have been combined into one call, but the template designer has no knowledge about this. (and he should not have imho). To avoid having redundant calls, some way of caching has to be implemented, but the code becomes more complicated. - if you use the custom functions, I believe your code becomes more complicated, because you have to make separate files for each given functionality, so you may lose a lot of the OO capabilities of your code. Has anyone of you already made a site on this way? My purpose is to have a site with different templates/skins which can be TOTALLY different: the template designers can decide on their own what information they want to show, ... In general, I want the template designer to have 'access' to the whole database/data files/... on an efficient way (no redundant calls, ...), so he can do with it whatever he wants to. Monte: What did you mean with your last sentence: 'You could then use a prefilter to transpose {$myvar} to one of the statements given above'. I'm still new to templates and the idea behind it, but I like it very much. I just don't like the approach of using them: I think the direction of data should be 'template asks to the code to retrieve data, to be shown on the site' and not 'the code gives data to the template, to be shown on the site, and the template should be happy with this'. I believe that with the first method you can make much more dynamic sites. Are there any tutorials available which go deeper into templates & how to use them? I understand how they work, what you can do with them, but I can't find a good way to use them in big projects. Thanks, Peter -----Original Message----- From: Monte Ohrt [mailto:monte@ispi.net] Sent: maandag 5 januari 2004 15:49 To: Peter Billen Cc: Smarty Dev Subject: Re: [SMARTY-DEV] feature request 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 (#2025) next »