else should not take any arguments

Armen Baghumian <[email protected]> Tue, 16 Oct 2007 13:44:25 +0330
Newsgroups gmane.comp.php.smarty.devel
Message-ID <[email protected]>
--MP_gDzDB095bF1xkYQkyQ9usNd
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

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
--MP_gDzDB095bF1xkYQkyQ9usNd
Content-Type: text/x-patch; name=elseif.patch
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename=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__);


--MP_gDzDB095bF1xkYQkyQ9usNd
Content-Type: text/plain; charset=us-ascii

-- 
Smarty Development Mailing List (http://smarty.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--MP_gDzDB095bF1xkYQkyQ9usNd--