Categories > TinyButStrong general >

How to create menu with TBS ?

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: htvu
Date: 2006-03-31
Time: 04:37

How to create menu with TBS ?

I have an array store menu items data with form (level, title). Level have value 0 or 1. How to display all item' title as a menu. if item's level = 1, it will be indent.
My code is listed below but it not work.

PHP side:

<?php
$result[0] = array(0, 'Home');
$result[1] = array(0, 'Service');
$result[2] = array(1, 'service 1');
$result[3] = array(1, 'service 2');
$result[0] = array(0, 'Product');
$result[1] = array(0, 'product 1');
$result[2] = array(1, 'product 2');
$result[3] = array(1, 'product 3');

$TBS = new clsTinyButStrong ;
$TBS->LoadTemplate('template.html') ;
$TBS->MergeBlock('blk_res',$result) ;
$TBS->Show() ;
?>


HTML side (source):

<html>
<body>
<table width="300" border="1" align="center" cellpadding="4" cellspacing="0">
  <tr>
    <td><table width="100%" border="0" cellspacing="1" cellpadding="0">
        <tr>
          <td width="20" bgcolor="#CFE7CF">&#8226;</td>
          <td colspan="4" bgcolor="#CFE7CF" class="title-section">
                  [blk_res.level;block=tr;when [blk_res.level]=0;extend=1]
          </td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td width="20" valign="middle" bgcolor="#FFF5D2">&deg;</td>
          <td width="120" colspan="3" bgcolor="#FFF5D2">
                  [blk_res.level;block=tr;if [blk_res.level]=1]
          </td>
        </tr>
      </table></td>
  </tr>
</table>
</body>
</html>
By: htvu
Date: 2006-03-31
Time: 05:12

Re: How to create menu with TBS ?

ah, I have an addition request that is: if an item is not displayed, the <tr> tag suround it will be removed too. How to do that ?
By: Skrol29
Date: 2006-03-31
Time: 11:26

Re: How to create menu with TBS ?

Hello,

Looking at you snippet, it seems that you should not use parameter "extend". Your block has two sections, and each section is defined by one <tr></tr> only.

It also seems that you've used parameter "if " instead of "when" in the second section. Parameter "if " is for a field only, parameter "when" is for a block only.
By: htvu
Date: 2006-03-31
Time: 17:31

Re: How to create menu with TBS ?

Thanks Skrol29,
I made it work with template code below:

<html>
<body>
<table width="300" border="1" align="center" cellpadding="4" cellspacing="0">
  <tr>
    <td>
       <table width="100%" border="0" cellspacing="1" cellpadding="0">
          <tr>
             <td align="center" bgcolor="#CFE7CF">&#8226;</td>
             <td colspan="2" bgcolor="#CFE7CF" class="title-section">
    [blk_res.name;block=tr;if [blk_res.level]=0;onshow;magnet=tr]</td>
          </tr>
          <tr>
             <td>&nbsp;</td>
             <td align="center" valign="middle" bgcolor="#FFF5D2">&deg;</td>
             <td bgcolor="#FFF5D2">
    [blk_res.name;block=tr;if [blk_res.level]=1;onshow;magnet=tr]
             </td>
          </tr>
       </table>
     </td>
  </tr>
</table>
By: htvu
Date: 2006-03-31
Time: 17:34

Re: How to create menu with TBS ?

Array to merge with this template have form:

$result[0] = array('level'=>0, 'name'=>'Home');