Categories > TinyButStrong general >

Conditional block display

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: retro
Date: 2005-06-07
Time: 16:45

Conditional block display

I need to hide a part of code if some of variables are not set.

I am using slightly modified php code from the examples:
$TeamList[0] = array('team'=>'Eagle'  ,'total'=>'458');
$TeamList[0]['matches'][] = array('town'=>'London','score'=>'253','date'=>'1999-11-30');
$TeamList[0]['matches'][] = array('town'=>'Paris' ,'score'=>'145','date'=>'2002-07-24');

$TeamList[1] = array('team'=>'Goonies','total'=>'281');

$TeamList[2] = array('team'=>'MIB'    ,'total'=>'615');
$TeamList[2]['matches'][] = array('town'=>'Dallas'    ,'score'=>'362','date'=>'2001-01-02');
$TeamList[2]['matches'][] = array('town'=>'Lyon'      ,'score'=>'321','date'=>'2002-11-17');
$TeamList[2]['matches'][] = array('town'=>'Washington','score'=>'245','date'=>'2003-08-24');

$TBS = new clsTinyButStrong ;
$TBS->LoadTemplate('template.html') ;
$TBS->MergeBlock('mb','array','TeamList') ;
$TBS->MergeBlock('sb','array','TeamList[%p1%][matches]') ;
$TBS->Show() ;

and template code

...
<table width="400" border="1" align="center" cellpadding="4" cellspacing="0" bordercolor="#3399CC">
  <tr>
    <td><strong>Team:</strong>[mb.team;block=tr]<br>
      <strong>Total score:</strong> [mb.total]<br>
      <br>
     <table border="1" align="center" cellpadding="2" cellspacing="0">
        <tr bgcolor="#CACACA">
          <td width="30"><u>Position</u></td>
          <td width="150"><u>Town</u></td>
          <td width="50"><u>Score</u></td>
          <td width="100"><div align="center"><u>Date</u></div></td>
        </tr>
        <tr bgcolor="#F0F0F0">
          <td>[sb.#]</td>
          <td>[sb.town]</td>
          <td><div align="right">[sb.score;block=tr;p1=[mb.$]]</div></td>
          <td><div align="center">[sb.date;frm='dd.mm.yyyy']</div></td>
        </tr>
        <tr bgcolor="#E6E6E6">
          <td>[sb.#]</td>
          <td>[sb.town]</td>
          <td><div align="right">[sb.score;block=tr]</div></td>
          <td><div align="center">[sb.date;frm='dd.mm.yyyy']</div></td>
        </tr>
      </table>
  </td>
  </tr>
</table>
...

what i want  is to hide whole "sb" table if "sb" is not defined, but to show the "mb" part. is there a way to achieve this? I searched on forum and in manual, and i haven't found a solution.
By: Skrol29
Date: 2005-06-07
Time: 18:36

Re: Conditional block display

Hello Retro,

You can delete the table when there is no data in the sub-block by adding a NoData section containging an [onshow] tag .

example:
        <tr>
          <td></td>
          <td></td>
          <td>[sb;block=tr;nodata]</td>
          <td>[onshow;magnet=table]</td>
        </tr>
By: retro
Date: 2005-06-07
Time: 18:47

Re: Conditional block display

thank you very much.