Categories > TinyButStrong general >

dynamic sub-blocks

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: Jared
Date: 2013-02-28
Time: 03:53

dynamic sub-blocks

I have working code the produces a 3 level deep tree. Here is the code:

$data[1]['label'] = 'Top Level A';
$data[1]['sub'][0]['label'] = 'Sub Level A1';
$data[1]['sub'][0]['sub'][0]['label'] = 'Sub Level A1 - A';
$data[1]['sub'][0]['sub'][1]['label'] = 'Sub Level A1 - B';

$data[2]['label'] = 'Top Level B';
$data[2]['sub'][0]['label'] = 'Sub Level B1';
$data[2]['sub'][0]['sub'][0]['label'] = 'Sub Level B1 - A';
$data[2]['sub'][0]['sub'][1]['label'] = 'Sub Level B1 - B';

$tbs->MergeBlock('top',$data);
$tbs->MergeBlock('sub1','array',"data[%p1%][sub]");
$tbs->MergeBlock('sub2','array',"data[%p1%][sub][%p2%][sub]");

<ul>
  <li><a href='#'>Data</a></li>
  <li><a href='#'>[top.label;block=li]</a>
    <ul>
      <li><a href='#'>[sub1.label;block=li;p1=[top.$];bmagnet=ul]</a>
        <ul>
          <li><a href='#'>[sub2.label;block=li;p1=[top.$];p2=[sub1.$];bmagnet=ul]</a></li>
        </ul>
      </li>
    </ul>
  </li>
</ul>

This is the results
<ul>
  <li><a href='#'>Current Location</a></li>
  <li><a href='#'>Top Level A</a>
    <ul>
      <li><a href='#'>Sub Level A1</a>
        <ul>
          <li><a href='#'>Sub Level A1 - A</a></li>
          <li><a href='#'>Sub Level A1 - B</a></li>
        </ul>
      </li>
    </ul>
  </li>
  <li><a href='#'>Top Level B</a>
    <ul>
      <li><a href='#'>Sub Level B1</a>
        <ul>
          <li><a href='#'>Sub Level B1 - A</a></li>
          <li><a href='#'>Sub Level B1 - B</a></li>
        </ul>
      </li>
    </ul>
  </li>
</ul>

I would like some help creating some MergeBlock and template code that can handle an arbitrary depth.

I do not know how many levels deep my tree will become over time.

I was thinking about counting my array elements and building my MergeBlock calls inside a loop - not sure how that will work yet.

I do not have a good plan for how to build the dynamic template.

Any help / suggestions would be greatly appreciated.
By: Jared
Date: 2013-02-28
Time: 21:24

Re: dynamic sub-blocks

Here are a couple solutions I am considering.

  1) application code that updates a static template and controller code for the MergeBlock method calls any time tree depth changes.
  2) do it in javascript - convert php arrays to json and insert into dom

Anyone have other ideas?
By: Skrol29
Date: 2013-03-03
Time: 14:01

Re: dynamic sub-blocks

They are some solution for hierarchical menus at the Tips & Trics forum.
By: Jared
Date: 2013-03-05
Time: 22:19

Re: dynamic sub-blocks

Hi Skrol,

I am working through the solutions in the tips forum.

I am working through this problem based on you post here: http://www.tinybutstrong.com/forum.php?thr=1833

Do you have an example of that solution using an array instead of multiple queries?

I am also working through the example posted here: http://www.tinybutstrong.com/forum.php?msg_id=8926

But this solution differs significantly from your solution. I can modify my array to fit a solution, but I don't want to add a separate class to implement MBt's solution if I do not have to.

Thanks for the hard work you do with TBS!

- Jared