compiler-block functions (again, sorry)
| From: | M Mohr | Date: | Fri, 10 Jan 2003 12:18:06 +0000 |
| Subject: | compiler-block functions (again, sorry) | ||
| Groups: | php.smarty.dev | ||
| Request: | Send a blank email to php-smarty-dev+get-509@lists.php.net to get a copy of this message | ||
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