Re: Block functions
| From: | Anders Janson | Date: | Tue, 26 Mar 2002 08:43:11 +0000 |
| Subject: | Re: Block functions | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-3342@lists.php.net to get a copy of this message | ||
Ivo Jansch wrote:
> Hello,
>
> Andrei Zmievski wrote:
>
> > $content will be null for the opening tag so you can easily test whether
> > you are being called for opening/closing tag by using isset($content).
>
> What will it be when there's nothing between the tags? (for example,
> {table cols=3}{/table}
> Is it still possible to distinguish between start and end?
I have not downloaded and tried it yet, but I suppose you can test for "empty
string" vs "null".
>
>
> > Block functions take precedence over custom functions with the same
> > name. Also, you can pass attributes to the closing tag, e.g. {/table
> > foo=yes}.
>
> What about attributes passed to the opening tag, will they be passed to
> the closing tag as well? {table cols=3}stuff{/table} seems a logical
> thing to do, but would the cols param then be available in the closing
> tag, or do we have to use global vars to remember them?
There were discussions about a tag stack, and an arguments stack for this
kind of block functions.
I think that would be the best solution to handle all sorts of situations.
For example where arguments are needed in the opening tag, but used in the
closing tag.
Or when an inner tag needs to know parameters from an outer tag (context
aware tags!).
While it would be possible to implement this yourself in all custom tags you
write, it would be much more convenient if Smarty already had this
functionality. That would also make all tags compatible.
>
>
> Isn't it possible to call the handler only once, with all parameters?
Maybe, maybe not... I think it is more flexible to have two calls.
>
> Most of the time, you have 1 piece of output from a set of
> opening/closing tags. Also, I think it's going to be inconvenient that
> you don't have the contents in the start tag.
>
> Take for example {link
> url=http://www.phpinsider.com}Test{/link}.
> Only in the closing tag I know that there's something in between the
> tags, but in the opening tag, I would like to check that, so my opening
> will not generate the <a href=""> stuff.
One yucky solution would be to put the URL argument in the closing tag...
ptoii... :)
Again, I have not looked at the code, but Smarty used to handle things quite
straight forward earlier.
Contents *after* the opening tags would not be known by the time Smarty
processes the opening tag. That would require recursive algorithms, or a
multi-pass compiler. I don't think we want the overhead of that, just because
it gets a little more convenient.
However, this link example demonstrates the need for the argument stack :)
The closing tag could examine the top of the stack to find the URL.
So... Andrei, please... stacks!!! ;)
/Anders