Categories > TinyButStrong general >

MergeBlock with Conditional display

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: Marcos Borges
Date: 2006-01-25
Time: 04:41

MergeBlock with Conditional display

I would like to know as I can show given conditional display with mergeblock.
example
--------------------PHP------------START-----
$arr[0]['nome'] = 'Product1';
$arr[0]['price'] = 2.22;
$arr[0]['display'] = 'Y';
$arr[1]['nome'] = 'Product2';
$arr[1]['price'] = 4.23;
$arr[1]['display'] = 'N';
$arr[2]['nome'] = 'Product3';
$arr[2]['price'] = 1.23;
$arr[2]['display'] = 'Y';
$arr[3]['nome'] = 'Product4';
$arr[3]['price'] = 5.23;
$arr[3]['display'] = 'N';
$TBS->LoadTemplate('products.html')
$TBS->MergeBlock('blkProducts',$arr);
$TBS->Show();
--------------------PHP------------END-----

-----------------TEMPLATE------------START-----
<table>
<tr>
<td>Produtc</td>
<td>Price</td>
</tr>
[blkProducts;block=begin;]
<tr>
<td>[blkProducts.name]</td>
<td>[blkProducts.price]</td>
</tr>
[blkProducts;block=end;]
-----------------TEMPLATE------------END-----

If blkProducts.display = 'Y' show blkProducts.price
else if blkProducts.display = 'N' no show blkProducts.price

how to make this?
By: Skrol29
Date: 2006-01-25
Time: 11:23

Re: MergeBlock with Conditional display

Hello, here is first solution :
<table>
  <tr>
    <td>Produtc</td>
    <td>Price</td>
  </tr>
  <tr>
    <td>[blkProducts.name;block=tr;when [blkProducts.display]='Y']</td>
    <td>[blkProducts.price]</td>
  </tr>
  <tr>
    <td>[blkProducts.name;block=tr;default]</td>
    <td>Price not available</td>
  </tr>

Note that I've used the simplified syntax for blocks (parameter "block=tr")

Another solution is to put the condition on the Price field only:
<table>
  <tr>
    <td>Produtc</td>
    <td>Price</td>
  </tr>
  <tr>
    <td>[blkProducts.name;block=tr]</td>
    <td>[blkProducts.display;if [val]='Y';then [blkProducts.price];else 'Price not available']</td>
  </tr>
By: Marcos Borges
Date: 2006-01-25
Time: 13:52

Re: MergeBlock with Conditional display

Thanks Scroll29 !!!