Re: [SMARTY-DEV] Block extensibility?

From: Date: Wed, 26 Mar 2003 11:52:29 +0000
Subject: Re: [SMARTY-DEV] Block extensibility?
References: 1 2 3  Groups: php.smarty.dev 
Request: Send a blank email to php-smarty-dev+get-1029@lists.php.net to get a copy of this message
On Wed, Mar 26, 2003 at 12:43:06PM +0100, Nico Sabbi wrote: > > > > i don't know which one you mean, but i'm pretty sure it is not anyway. > > > > > In this case, can I write blocks such as the following one? > > > {if} > > > {elsif}* repeated an unlimited (and not know a-priori) number of > times > > > {else} > > > {/if} > > > > blocks in smarty a very restricted. for something like the above you > > would have to use your own compiler functions. see: > > > > http://smarty.php.net/manual/en/plugins.compiler.functions.php > > > > (hint) maybe you don't need to patch smarty, since you can: > > register_compiler_function('myif', 'myif_open); > > register_compiler_function('/myif', 'myif_close); > > > > then you can implement a closing and an opening function (and > > optionallyy my_else etc., of course) and write in your template: > > {myif ...} ... {/myif} > > > > > And in this case how can I instruct Smarty that {myelse} is part of {myif} > {/myif} syntactic block ? you can not. the smarty parser is regexp-based and very slim. it does not do these syntactic checks. you'll notice that when you have errors in your template (like a closing {/if} whithout an opening one). the template-compiler does not raise an error, but the template has php-syntax-errors. so you'll have to maintain your own stack of myif-blocks and check inside the myelse-function whats the top-open-myif it belongs to. > Thanks.

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