Re: [SMARTY-DEV] compilerblock plugins patch

From: Date: Mon, 02 Dec 2002 23:18:00 +0000
Subject: Re: [SMARTY-DEV] compilerblock plugins patch
References: 1 2 3  Groups: php.smarty.dev 
Request: Send a blank email to php-smarty-dev+get-364@lists.php.net to get a copy of this message
On Mon, Dec 02, 2002 at 09:36:15PM +0100, M Mohr wrote: > 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. > > i thought about it. i don't think _compile_block_tag() can be recycled > to handle compiler-block functions. but _compile_compiler_tag() can > be. i think i can modify traditional compiler-function-handling to use > optional closing-tags, so the same functionality that my compilerblock- > functions provided would be achieved. > > this would require no change in the api, just a little update im the docs. > i think i can come up with a pach soon :) ^^^^ ouch, should read patch, of course here it is. no need for a compilerblock-plugin anymore. you can use your compiler-functions as "{func..}..{/func}" or simply as "{func..}". $smarty->compiler_start_tag is a boolean that can be asked inside a compiler-functions if it was called as "{func}" or as "{/func}" i like this much better than my first approach. regards messju > this would require no change in the api, just a little update im the docs. > i think i can come up with a pach soon :) > > have fun > messju > > > 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 > > > > Monte > > > > 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-cvs-Ref/Smarty_Compiler.class.php Sun Dec 1 13:49:10 2002 --- Smarty_Compiler.class.php Tue Dec 3 00:10:00 2002 *************** class Smarty_Compiler extends Smarty { *** 52,53 **** --- 52,54 ---- var $_init_smarty_vars = false; + var $_compiler_tag_stack = array(); // keeps track of compiler-functions' tag_args *************** class Smarty_Compiler extends Smarty { *** 347,348 **** --- 348,375 ---- { + + if ($tag_command{0} == '/') { + /* handle closing tag */ + $this->compiler_start_tag = false; + $tag_command = substr($tag_command, 1); + + /* find corresponding opening tag */ + $tag_args=null; + while ($tag = array_pop($this->_compiler_tag_stack)) { + if ($tag[0]==$tag_command) { + $tag_args = $tag[1]; + break; + } + } + if ($tag_args===null) { + /* opening tag not found */ + $this->_syntax_error($message, E_USER_WARNING); + } + + } else { + /* handle opening tag */ + $this->compiler_start_tag = true; + $this->_compiler_tag_stack[] = array($tag_command, $tag_args); + + } + $found = false;
« previous php.smarty.dev (#364) next »