proposal for tagnesting (begin/end tags)

From: Date: Tue, 11 Dec 2001 21:59:54 +0000
Subject: proposal for tagnesting (begin/end tags)
Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-2258@lists.php.net to get a copy of this message
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? Greetings, Ivo -- Ivo Jansch <ivo@ibuildings.nl> ibuildings.nl BV - information technology http://www.ibuildings.nl

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