Re: [SMARTY-DEV] compilerblock plugins patch

From: Date: Mon, 02 Dec 2002 15:48:24 +0000
Subject: Re: [SMARTY-DEV] compilerblock plugins patch
References: 1 2  Groups: php.smarty.dev 
Request: Send a blank email to php-smarty-dev+get-359@lists.php.net to get a copy of this message
Hello, On Mon, Dec 02, 2002 at 09:13:37AM -0600, Monte Ohrt wrote: > I'm wondering, what if we changed the block functions to use this > method, does anything break? (besides needing to be recompiled) If not, > this would keep the API simpler and no new documentation needed, maybe a > technical note adjustment. uh, i have to look further into the compiler, follow this. i just startet scratching on the surface with of it, i think. i read in the mailing list archive back in august that compiler-block-plugins are in planning, but it is unknown when they are done and i could not wait :) > Does your method resolve the issue of evaluating variables in a block > function at runtime? Problem outlined in this posting: > > > http://marc.theaimsgroup.com/?l=smarty-dev&m=103774868829224&w=2 yes it should. it was my main intention to achieve something like this, since "normal" block-functions are not capable of it. i wanted to have my own iterators and looked for a generic api for it. for example i can iterate over the lines of a csv-file like this: [csv_test.tpl] {csv varname=try filename=csv_test.csv} item: {$try->name} = {$try->value} ({$try->_is_first}, {$try->_is_last})<br> {/csv} with: [compilerblock.csv.php] function smarty_compilerblock_csv($tag_args, $start_tag, &$smarty) { extract($smarty->_parse_attrs($tag_args)); if (!isset($varname)) $smarty->trigger_error('$varname not set'); if (!isset($filename)) $smarty->trigger_error('$filename not set'); if ($start_tag) { return "\$this->_tpl_vars[$varname] = new CSV($filename); while(\$this->_tpl_vars[$varname]->next()): "; } else { return 'endwhile;'; } } the CSV-class i used here has a simple constructor opening the file and a next()-method that returs the next line or null at eof. i think it is unnecessary noise to dump it here. without a compilerblock function i think i would have had to read the full-file. but i think there are more uses for compiler-block-functions than just iterators. > Monte regards messju (sorry for my bad english. i am not a native english speaker, but i hope it's enough to be understood :) > On Mon, 2002-12-02 at 05:47, M Mohr wrote: > > hello, > > > > i patched smarty to support block-function at compile time. the > > compilerblock-function is searched as compilerblock.[name].php in the > > plugins_dirs and has precedence before simple (==old) > > compiler-funcions. > > > > alternatively you can register compilerblock-functions using > > $smarty->register_compilerblock_function(..). > > > > the function has to be declared as: > > > > function func($tag_args, $start_tag, &$smarty) ... > > > > or > > > > function smarty_compilerblock_csv($tag_args, $start_tag, &$smarty) ... > > > > where tag_args ar the (unparsed) arguments, like in the simple > > compiler-functions and $start_tag is a boolean indicating wether the > > function was called at the beginning or the end of the block. > > > > i attached the diff against the lates cvs-version. it's not small, but > > pretty simple, since it is a mainly a rip-off of > > Smarty_Compiler::_compile_block_tag() > > > > i would love to see it applied in Smarty-2.3.2 and i am willing to > > provide documentation for such plugins and to maintain this patch if > > necessary. > > > > any use for it? > > any comments? > > > > regards > > messju mohr > > > > ______________________________________________________________________ > > > > -- > > Smarty Development Mailing List (http://smarty.php.net/) > > To unsubscribe, visit: http://www.php.net/unsub.php > -- > Monte Ohrt <monte@ispi.net>

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