TinyButStrong - the PHP Template Engine
Categories > TinyButStrong general >

nested automatic subblocks

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

By: Jared
Date: 2012-08-28
Time: 02:54

nested automatic subblocks

Hi,

Is it possible to do something like this?
                            <tr id='[cal.$;block=tr;sub1=days]'>
                                <td >
                                  <a href="#" class="day">[cal_sub1.DATE;block=td;htmlconv=no;sub2=data]</a>
                                    <ul>
                                        <li><a href="#">[cal_sub2.ID;block=li]</a></li>
                                    </ul>
                                </td>
                            </tr>
By: Skrol29
Date: 2012-08-28
Time: 02:56

Re: nested automatic subblocks

Hi Jared,

The following should work:
       <tr id='[cal.$;block=tr;sub1=days]'>
        <td >
          <a href="#" class="day">[cal_sub1.DATE;block=td;htmlconv=no;sub1=data]</a>
         <ul>
          <li><a href="#">[cal_sub1_sub1.ID;block=li]</a></li>
         </ul>
        </td>
       </tr>
By: Jared
Date: 2012-08-29
Time: 03:23

Re: nested automatic subblocks

Hi,

Thanks for the fast response!

What would be the best way to merge an array like this:

Array
(
    [0] => Array
        (
            [29] =>
            [30] =>
            [31] =>
            [1] =>
            [2] =>
            [3] =>
            [4] => Array
                (
                    [0] => Array
                        (
                            [ID] => 3
                            [ORIGINATOR] => 1234
                            [PREPARED] => 2012-08-20
                            [taskName] => This is a test name
                            [taskDesc] => This is a test description.
                        )

                    [1] => Array
                        (
                            [ID] => 4
                            [ORIGINATOR] => 1234
                            [PREPARED] => 2012-08-20
                            [taskName] => This is a test name
                            [taskDesc] => This is a test description.
                        )

                )

        )

)
By: Jared
Date: 2012-08-29
Time: 23:33

Re: nested automatic subblocks

Ok, for my problem - the automatic subblock was not possible. Here is what I did instead.

The data model:
$data[0]['sub'][30]['sub'] = array();
$data[0]['sub'][31]['sub'] = array();
$data[0]['sub'][1]['sub'] = array();
$data[0]['sub'][2]['sub'] = array();
$data[0]['sub'][3]['sub'] = array();
$data[0]['sub'][4]['sub'][] = array (
  'ID' => '3',
  'ORIGINATOR' => '1234',
  'PREPARED' => '2012-08-20',
  'taskName' => 'This is a test name',
  'taskDesc' => 'This is a test description.'
);
$data[0]['sub'][4]['sub'][] = array (
  'ID' => '4',
  'ORIGINATOR' => '1234',
  'PREPARED' => '2012-08-20',
  'taskName' => 'This is a test name',
  'taskDesc' => 'This is a test description.'
);

The MergeBlock method calls:
$tbs->MergeBlock('cal','array','data');
$tbs->MergeBlock('sub1','array','data[%p1%][sub]');
$tbs->MergeBlock('sub2','array','data[%p1%][sub][%p2%][sub]');

And the template code:
<tr id='[cal.$;block=tr]'>
  <td >
    <a href="#" class="day">[sub1.$;block=td;p1=[cal.$]]</a>

    <ul>
      <li><a href="#">[sub2.taskName;block=_;p1=[cal.$];p2=[sub1.$];bmagnet=ul]</a></li>
    </ul>

    </td>
</tr>

- Jared