Re: [SMARTY-DEV] Bringing the {insert} functionality to other tags
| From: | Ivo Jansch | Date: | Thu, 05 Sep 2002 07:24:46 +0000 |
| Subject: | Re: [SMARTY-DEV] Bringing the {insert} functionality to other tags | ||
| References: | 1 2 3 4 | Groups: | php.smarty.dev |
| Request: | Send a blank email to php-smarty-dev+get-262@lists.php.net to get a copy of this message | ||
Hi Monte,
Monte Ohrt wrote:
"rendering pipeline" so each piece is clearly defined.While you're talking about a pipeline, I have a remark unrelated to caching: Wouldn't it be a Good Thing if template functions would *return* their result instead of echoing it? Currently we must echo, and the output is catched with output buffering. This makes re-using the functions in different contexts more difficult. Also, if they return a string, the string could be operated on.
Anyways, on to caching. I have had very little thought on how caching would work, so I'll try it now :-) One idea (and probably most workable) is to cache on a function-basis.Yes, this is how I currently handle caching. Funtions are functionality. Functionality is either static or dynamic. So the functions should determine if they need to be cached or not.
cache nothing and register which functions get cached, or cache everything and register which functions _don't_ get cached (currently how {insert} works).In all templates I've created with Smarty so far, the largest part is cachable, and there are a few dynamic things that shouldn't be cached, so the 'cache all unless registered as not-cachable' appeals most to me.
$this->register_cache_function('get_poll'); or: $this->register_nocache_function('get_poll'); // ???Or: $this->register_function('get_poll', SMARTY_NOCACHE); (I mean using bit flags. SMARTY_NOCACHE could be one of several flags that influence the tag.) Another thing I've been thinking about is a 'multistage parser'. Currently there's cached contents, uncached contents, and stuff you add in a pre- or postfilter. In other words, there are actually five stages in which you can insert contents: - compile-time - prefilter - first time rendering - second time rendering (the 'insert' tags) - postfilter Each of these stages has its own implementation, its own way of rendering (compiler functions, regular functions, insert tags, pre/postfilter functions), while it's fundamentally the same thing over and over again: Taking the template through another stage of rendering. What we could also do is generalize this principle, and make a multi-stage parser. When implementing a function or plugin, the application developer can determine at what stage the function gets inserted, like this: $this->register_function('get_poll', STAGE_3); $this->register_function('render_javascript_headerfunctions', STAGE_5); etc.. I've been thinking about this multistage approach ever since I needed to add stuff between the <head></head>, whenever a certain function was called from inside the template (currently I use a postfilter for this). The way the renderer should work is something like this: foreach tags { if ($this->_currentstage == $tag->renderstage()) {
// do the rendering thing..} else {
// leave the tag as is, the next stage will render it.} } Performance should not suffer, because you currently already have a 5 stage approach. It would just be a more generic way of handling stages (you could even add the possibility to configure the number of stages) Greetings, Ivo -- Ivo Jansch <ivo@ibuildings.nl> ibuildings.nl BV - information technology http://www.ibuildings.nl