Re: [SMARTY-DEV] compiler-block functions (again, sorry)
| From: | Andrei Zmievski | Date: | Fri, 10 Jan 2003 15:00:38 +0000 |
| Subject: | Re: [SMARTY-DEV] compiler-block functions (again, sorry) | ||
| References: | 1 | Groups: | php.smarty.dev |
| Request: | Send a blank email to php-smarty-dev+get-512@lists.php.net to get a copy of this message | ||
I would do it this way, but rather provide a stack, similar to block
functions, so that you can inspect it to see what functions enclose
youru current one.
On Fri, 10 Jan 2003, M Mohr wrote:
> Hello,
>
> I suggested support for compiler-block functions a while ago.
> Advanced template programmers would be able build their own while and
> for loops und things like switch and case statements.
>
> My first approach was ugly and extended the api by another plugin-type.
> That was bad.
>
> I want to come up with a more simpler patch now:
>
> RCS file: /repository/smarty/Smarty_Compiler.class.php,v
> retrieving revision 1.145
> diff -r1.145 Smarty_Compiler.class.php
> 477a478,486
> > if ($tag_command{0} == '/') {
> > /* handle closing tag */
> > $this->_compiler_tag_start = false;
> > $tag_command = substr($tag_command, 1);
> > } else {
> > /* handle opening tag */
> > $this->_compiler_tag_start = true;
> > }
>
>
> The only impact on backwards-compatibility is, that without this
> patch "{/func}" raised an error and is now accepted by the compiler.
> This should not be a problem. :)
>
> Additionly the compiler sets a flag, wether the function was called as
> an opening or a closing tag. Now the compiler-function can ask
> $smarty->_compiler_start_tag to see, how it was called and generate code
> accordingly.
>
> The compiler-function does not have to check this flag, of
> course. Non-block compiler-functions simply ignore this flag, as they
> do now. :)
>
> With that functionality, it should be possible to write (medium
> easily) functions like "foreach", "section" or "if" as compiler-
> plugins. I don't think it is necessary to have these basic constructs
> as plugin, but it shows the power of the simple compiler-block-patch
> above.
>
> Used in the right way it could empower the template-programmer to
> provide powerful functions to his/her designers that could lead to
> even simpler templates, as they are possible now.
>
> I would love to see this in smarty-cvs.
>
> have fun
> messju
>
> --
> Smarty Development Mailing List (http://smarty.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
-Andrei http://www.gravitonic.com/
As I was going up the stair, I met a man who wasn't there.
He wasn't there again today. I wish, I wish he'd stay away.
-Hughes Mearns