TinyButStrong - the PHP Template Engine
Categories > TinyButStrong general >

[TBS 3.8.1] Block shows even if the value to compare is zero (maybe enconding problem?)

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs

By: Timo
Date: 2014-03-28
Time: 10:28

[TBS 3.8.1] Block shows even if the value to compare is zero (maybe enconding problem?)

Hello,

i have currently an strange problem with TBY 3.1.8 in our project. We want to show an "Currently {specialprice} instead of {normalprice}".
If an {specialprice}  is set, it is every time lower than the {normalprice}.

So the 'instead of'-Layer should only show if an {specialprice} exists, is greater than zero, but less than {normalprice}.

The template syntax:

    <span class="prod_list_item_aprice">
    [onload;block=span;when [blk_gal.sprice] -+ [blk_gal.price]]
    [onload;block=span;when [blk_gal.sprice] +- 0.00]
        instead of [blk_gal.price;noerr;frm='0.000,00'] &euro;
        </span>

The Block is correct merged and the value [sprice] is an double of 0.00.

  [8] => Array
        (
            [id] => 32XXX
            [art_link] => link.htm
            [art_rlink] => /product_details.php?art=S0130XXXXX
            [art_nr] => S0130XXXXX
            [name] => Product 1
            [price] => 9.00
            [sprice] => 0.00
        )

I've casted the variable as an double, as an integer and even as string and used string compare (!=).
But the 'instead of'-Layer shows every time. If I try to compare any math value the result is the same. It dosn't work correctly.

In an other project  the same template syntax works like an charm.
So I don't get it. Why I coudn't compare an simple numerical value against zero or an other number.
The only thing I could think of going wrong, is the encoding of values, because we multibyte_encode every Array-Member - if an REGEX don't match an number - into utf-8.



By: Skrol29
Date: 2014-03-28
Time: 14:24

Re: [TBS 3.8.1] Block shows even if the value to compare is zero (maybe enconding problem?)

Hi Timo,

First try with [onshow] instead of [onload].
[onload] automatic fields are merged during the LoadTemplate(). I.E. when your [blk_gal] block is not yet merged.

Another simple solution is to calculate a dedicated column for this purpose in you query.
    (CASE WHEN (sprice < price) AND (sprice > 0 ) THEN sprice ELSE NULL END) AS sprice_display

And in your template:
<span class="prod_list_item_aprice">
  instead of [blk_gal.sprice_display;noerr;frm='0.000,00';magnet=span] &euro;
</span>
   
By: Timo
Date: 2014-04-01
Time: 09:48

Re: [TBS 3.8.1] Block shows even if the value to compare is zero (maybe enconding problem?)

Thanks for the reply.
I've had swapped the value compare to the SQL-Statement too. But even then - in the described scenario - I could only test against existence of an variable and nothing more.
So I've simply created an additional field in the result to do that.

Today i've changed it to [onshow] and that was the solution. Now I can compare values like normal.
Thanks for your help.