1
Maxter
problem with smarty and logical operators
  • 2004/10/12 13:19

  • Maxter

  • Just popping in

  • Posts: 6

  • Since: 2002/1/3 1


i'm workin on some modification of the xdirectory module and i found a problem with the use of the || (or) logical operator on smarty.

i will be verbose, for all that people don't knowing this module :)
xdirectory pass to smarty templates the 'link' array, containing the two variables involved in the problem.
these variables are $link.logourl (containing the name of the logo image for a business entry) and $link.premium (that select some additional displaying features for a business entry).

if i try to set a logical operator like this, it does not work:

<{if $link.premium != "" || Slink.logourl != "0" }>
<
img src="image_for_business_without_logo.jpg">
<{else}>
<
img src="shots/<{$link.logourl}>">
<{endif}>


if i set only a 'if $link.premium or a 'if $link.logourl' conditional statement, this work fine, but setting both the variables as conditional, lets work only the $link.premium condition
more clearly, a business entry without a logo will show no image because the img tag will result like this:

<img src="shots/">


viceversa if i set a logical operators like this, it will work:

<{if $link.premium == "" || Slink.logourl == "0" }>
<
img src="shots/<{$link.logourl}>">
<{else}>
<
img src="image_for_business_without_logo.jpg">
<{endif}>


it seems to me very strange, but maybe there is something of smarty i didn't understand...

anyone can tell me if it is a problem of smarty or of the xoop's smarty implementation (o may be a my mistake? )

Many thanx and sorry for my bad english

Max

2
Mithrandir
Re: problem with smarty and logical operators

Only thing I can see is that you write
<{if $link.premium != "" || Slink.logourl != "0" }>

and not
<{if $link.premium != "" || $link.logourl != "0" }>


If this is just a typo in the post try putting in some brackets like this:
<{if (($link.premium != "") || ($link.logourl != "0")) }>

3
Draven
Re:problem with smarty and logical operators
  • 2004/10/12 15:44

  • Draven

  • Module Developer

  • Posts: 337

  • Since: 2003/5/28


Also be sure to check the smarty doc site for proper use of the || operator, my suggestion would be to use OR instead.

http://smarty.php.net/manual/en/language.function.if.php

Quote:

{* an example with "or" logic *}
{if $name eq "Fred" or $name eq "Wilma"}
...
{/if}

{* same as above *}
{if $name == "Fred" || $name == "Wilma"}
...
{/if}

{* the following syntax will NOT work, conditional qualifiers
must be separated from surrounding elements by spaces *}
{if $name=="Fred" || $name=="Wilma"}
...
{/if}

4
Maxter
Re: problem with smarty and logical operators
  • 2004/10/12 16:53

  • Maxter

  • Just popping in

  • Posts: 6

  • Since: 2002/1/3 1


thanks for the answers...

Mithrandir:
yes, the Slink.logourl is a typo in the post, i checked many times the syntax :)
before posting i also tried to separate the condition with bracket, without any result :-/

Draven:
i tried also the use of OR instead of ||, again without any result, and i have read the smarty documentation many times searching for any possible idea.

I will try to reproduce this error in another page containing only the $link array or another array, to see it the error happen again.

5
christian
Re: problem with smarty and logical operators
  • 2005/5/22 20:23

  • christian

  • Just can't stay away

  • Posts: 401

  • Since: 2002/2/24


I have the same problem with wfchannel_index.html.

This is ok
<{if $article.headline != "Saveurs régionales"}>
<{$article.headline}>
<{/if}>

But this lines are not implemented

<{if substr($article.headline,1,4) != "Menu"}>

<{if $article.headline != "Saveurs régionales" or $article.headline != "Menu de saison"}>

Have you a idea ?

6
Dave_L
Re: problem with smarty and logical operators
  • 2005/5/22 23:07

  • Dave_L

  • XOOPS is my life!

  • Posts: 2277

  • Since: 2003/11/7


Quote:
<{if substr($article.headline,1,4) != "Menu"}>


This works for me. Note that substr(...,1,4) returns four characters starting at the second character of the string. For example, substr("abcdef",1,4) is "bcde".

Quote:
<{if $article.headline != "Saveurs régionales" or $article.headline != "Menu de saison"}>


This also works. But it doesn't make much sense, since the if-clause will always be true. I.e., if A != B, as they are in your case, then the expression (C != A or C != B) is a tautology (always true).

7
christian
Re: problem with smarty and logical operators
  • 2005/5/22 23:25

  • christian

  • Just can't stay away

  • Posts: 401

  • Since: 2002/2/24


Thousand thanks Dave, it's ok now

Login

Who's Online

326 user(s) are online (219 user(s) are browsing Support Forums)


Members: 0


Guests: 326


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Nov 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits