else should not take any arguments

View: New views
1 Messages — Rating Filter:   Alert me  

else should not take any arguments

by Armen Baghumian-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi guys,

Several days ago I just had a problem with elseif statement, as it is
specified in documentation these is not any tag called "else if" but I
used that tag and it just executed the else statement and ignored the
if itself.

for example:

{assign var="test" value="blah"}

{if $test != 'blah'}
    Dummy
{elseif $test == 'str'}
    Blah Blah
{/if}

{if $test != 'blah'}
    Dummy2
{else if $test == 'str'}
    Blah2 Blah2
{/if}

which expected output is blank page but it shows "Blah2 Blah2".
Yes this is not smarty bug but it is template designer mistake. IMHO it
is nice to throw an error in such cases then template designer can
correct the mistake.

another example of this situation is:

{if 'blah' != 'blah'}
    Dummy2
{else asdasdasdasdasd asd asdasda}
    Blah Blah
{/if}

as you can saw else ignores any arguments.
I come here with a tiny patch for this situation, it is attached with
this email, hope it could be usefull.

Best Regards,
Armen
[elseif.patch]

Index: libs/Smarty_Compiler.class.php
===================================================================
RCS file: /repository/smarty/libs/Smarty_Compiler.class.php,v
retrieving revision 1.399
diff -r1.399 Smarty_Compiler.class.php
475a476,477
>                 if ($tag_args != null)
>                     $this->_syntax_error('{else} should not take any arguments', E_USER_ERROR, __FILE__, __LINE__);



--
Smarty Development Mailing List (http://smarty.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
LightInTheBox - Buy quality products at wholesale price