1
fly2moon2
HELP: nested if condition doesn't give expected result for formatting
  • 2006/1/19 5:47

  • fly2moon2

  • Just popping in

  • Posts: 9

  • Since: 2005/8/17


Hi,


I'm developing a module and hitting problem at a template.

I want to use smarty engine to do some condition works so that it differetiates based on an array value to provide a different table cell (background) color.


It works find for the "<{if ($item_set[item_data].emp_id) == 'EMPLOYEE01'}>" statement. But when come to the inner/nested if statements for "<{if ($item_set[item_data].status) == 'LV'}>...", the checking doesn't output result as expected (it points (class="others") instead of the (class="lv") when the value is 'LV')



<{section name=item_data loop=$item_set}>
<{if ($item_set[item_data].emp_id) == 'EMPLOYEE01'}>
<{if ($item_set[item_data].status) == 'LV'}><{else}><{/if}>
<{$item_set[item_data].status}>
<{/if}>
<{/section}>




Pls guide me what's wrong, and how I can deal with this problem.

Thanks a lot.
jl

2
Catzwolf
Re: HELP: nested if condition doesn't give expected result for formatting
  • 2006/1/19 5:59

  • Catzwolf

  • Home away from home

  • Posts: 1392

  • Since: 2007/9/30


The code and nest look fine to me.

Are you sure that this element of the array $item_set[item_data].status has the var you expect?

I suggest you do a print_r($item_set) and see if the key has the value you believe it has.

3
m0nty
Re: HELP: nested if condition doesnt give expected result for formatting
  • 2006/1/19 6:10

  • m0nty

  • XOOPS is my life!

  • Posts: 3337

  • Since: 2003/10/24


also use [code ] not on these forums ;)

would it not be tter also to define $item_set[item_data] in the php and just use if ($emp_id == ) in the template?

4
fly2moon2
Re: HELP: nested if condition doesn't give expected result for formatting
  • 2006/1/19 6:28

  • fly2moon2

  • Just popping in

  • Posts: 9

  • Since: 2005/8/17


Thanks John and m0nty,


I also thought that the array doesn't have any value of 'LV'. But, as seen in my code, I've already show up the value of <{$item_set[item_data].status}> at the table cell. I do see occurences of 'LV' in the table.

Result is not expected and I double-check at the html page source; I don't the condition pointing to the correct path.

thanks,
jl

5
fly2moon2
Re: HELP: nested if condition doesn't give expected result for formatting
  • 2006/1/19 6:39

  • fly2moon2

  • Just popping in

  • Posts: 9

  • Since: 2005/8/17


Hi all!


I've found out the problem. There must be some trailing spaces follow the array values. I use the truncate modifier to limit the string into 2 characters only, then it works!

<{if ($item_set[item_data].status|truncate:2:"") == 'LV'}>
     ....................



Thanks for your assistance!
jl

6
Catzwolf
Re: HELP: nested if condition doesn't give expected result for formatting
  • 2006/1/19 6:48

  • Catzwolf

  • Home away from home

  • Posts: 1392

  • Since: 2007/9/30


In your php did you use trim() on the var? If not I would suggest that you do :)

Nice catch :)

Login

Who's Online

283 user(s) are online (171 user(s) are browsing Support Forums)


Members: 0


Guests: 283


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