Re: [SMARTY] "if" with "or"-problem
| From: | messju mohr | Date: | Thu, 03 Apr 2003 12:16:02 +0000 |
| Subject: | Re: [SMARTY] "if" with "or"-problem | ||
| References: | 1 2 3 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-9055@lists.php.net to get a copy of this message | ||
On Thu, Apr 03, 2003 at 01:35:07PM +0200, Matthias Mohr wrote:
> Hi!
>
> I just have a small problem with an if-expression inside a smarty template:
>
> test.php:
> --------------------------------------------------
> $smarty->assign( "Flag1", 0 );
> $smarty->assign( "Flag2", 0 );
> $smarty->display( 'MyTpl.tpl' );
> --------------------------------------------------
>
> MyTpl.tpl:
> --------------------------------------------------
> <!-- Flag1={$Flag1}; Flag2={$Flag2} -->
> {if $Flag1|default:0 eq 1 or $Flag2|default:1 eq 1}
> true<br>
> {else}
> false<br>
> {/if}
> --------------------------------------------------
>
> The result is as follows:
> --------------------------------------------------
> <!-- Flag1=0; Flag2=0 -->
> true
> --------------------------------------------------
>
> But why, both Flags are 0?
> Does the default-modifier don't work correct?
> Or am I doing something wrong?
it depends on what you would consider "correct".
default uses the default value for the integer 0 (or the boolean
false), but not for the string "0".
so if you do
$smarty->assign( "Flag1", "0" );
$smarty->assign( "Flag2", "0" );
"false" is printed.
but be aware: if you do {assign var=Flag2 value=0}, $Flag2 is a string
not an int. smarty treats all plugin-parameters as strings.
greetings
messju
> BTW, it's smarty v2.4.2 and php 4.3.1
>
> with regards,
> Matthias