Re: proposal for tagnesting (begin/end tags)

From: Date: Wed, 12 Dec 2001 16:09:57 +0000
Subject: Re: proposal for tagnesting (begin/end tags)
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-2266@lists.php.net to get a copy of this message
On Tue, 11 Dec 2001, Ivo Jansch wrote: > Hello, > > I've seen some people asking for begin and end tags before, and I need > this feature, so I'm willing to implement it. But before I do so, I'd > like to discuss the best way to do it. > > My idea is based on this: > > currently, there's a regular expression that separates tags from > non-tag-content. Basically, this gives two arrays (one with tags, the > other with between-tag-content), which are, after rendering the tags, > interleaved by Smarty. > > My though was to make this interleaver a bit more clever. If a tag has > an ending tag defined (which could be done using an extra parameter in > the register_custom_function call), than the interleaver would first > have to collect the rest of the content and tags, until it finds the > endtag. At that point, it should feed everything between the begin and > end tag to the taghandler. > > Two possibilities: either begin and end tag have separate handlers, and > the stuff between the two tags is passed to either one of them, or > there's one handler, to which the betweenstuff is passed. > > The tagmerger would mean a little recursion I guess, because inside > begin and end tags, there may be other tags, which may also have a begin > and end tag. > > To illustrate my proposed approach with an example, suppose the > following template: > > {link url="http://smarty.org"}Content inside the > {bold}tag{/bold}.{/link} > > The interleaver should, when encountering the link tag, do nothing, but > remember that everything from now on must be stored, and, once /link is > encountered, fed to the link taghandler. > > I only foresee difficulties when the template is inconsistent (for > example {tag1}{tag2}{/tag1}{/tag2}. This should generate an error > somehow. This is doable by maintaining some tag stack. > > What do you think of this? Does this look like something that's doable > and useful? Shall I give it a try? I have it on my TODO list for next major version, so it is in the plans. I think the best way to make this work is simply to insert ob_start() right after opening tag, and then use ob_get_contents() to pass everything inbetween to the closing tag handler. Voila. -Andrei * 2 + 2 = 5 for extremely large values of 2. *

« previous php.smarty.general (#2266) next »