Categories > TinyButStrong general >

simplify conditional display

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: kle_py
Date: 2011-08-23
Time: 18:06

simplify conditional display

I would like to know if You have a better solution than the one i attach here.

In a simple menu structure i would like to have a different display depending on the quantity of subitems. If there there is only one item, i would like to skip the submenu, and get the link directly in the "main" menu link.
Currently i made a model work like this:
<ul>
<li>[onshow_1;block=li;when [blk1.#] -+ 2]<a href="[blk1.url;block=a]">[blk1.category]</a>
</li>

<li>[onshow_1;block=li;default]<b>[blk2.category;block=b;headergrp=category]</b>
    <ul><li><a href="[blk2.url;block=li]">[blk2.doc_title]</a></li></ul>
</li>
</ul>
Possibly there is a more elegant way to achieve the same ? What bothers me a little is that i need to merge two blocks blk1 + blk2 to get this work, when using "only" blk1 always the second block is shown, which is not correct.

But thanks anyway for this great library. it helps me a lot
By: Skrol29
Date: 2011-08-24
Time: 00:20

Re: simplify conditional display

Hi Kle,

I'm surprised that your solution is working as you expect when they are several records. It seems to me that the result won't be good HTML.

It's difficult to have a nice solution because it need to delete on of the block after the merge.
It would be easier if you could have the count of record before to merge the block. Is is possible ?

By: kle_py
Date: 2011-08-24
Time: 14:35

Re: simplify conditional display

Hia skrol29,

yes indeed i can fetch the count before the merge, and have the conditional sections identified onload.

And You are right, my html is a little bit ugly for multiple records, because after the headergrp section the <ul> - tag is missing (testing with parentgrp does the same :( ).

ok, thanks for your reply. I think for a quick solution i can take the "headers" from a separate array to improve the html. besides i will have a look again at the sub-blocks examples.
By: Skrol29
Date: 2011-08-26
Time: 22:50

Re: simplify conditional display

Let's say you have the number of record in the global variable $count, there here is kind of solution :

PHP:
$TBS->MergeBlock('b_choice', 'cond');
$TBS->MergeBlock('blk', $data);

HTML :
<ul>

  <li>[b_choice;block=li;when [var.count]=1]<a href="[blk1.url;block=a]">[blk1.category]</a></li>

  <li>[b_choice;block=li;when [var.count]!=1]<b>[blk2.category;block=li;parentgrp=category]</b>
    <ul>
       <li><a href="[blk2.url;block=li]">[blk2.doc_title]</a></li>
   </ul>
  </li>

</ul>