Categories > TinyButStrong general >

Automatically merge block with empty array before/onShow

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: Rudy
Date: 2010-04-04
Time: 13:59

Automatically merge block with empty array before/onShow

Hello,

Is there any way to have a block merged with an empty array automatically onshow by only defining this in the template?

I have the following situation: In an application there is one template which has regular merged fields and blocks and some that can't be merged before show because ajax should do that by loading the samte template and using getblocksource, then merging the data and returning only one of the blocks. But for this to work those blocks need to be merged with an empty array to avoid invalid html for javascript-operations after onshow - and to show that we are just loading those parts.

Example:

HTML:
<div id="musicians">
  <div id="list">
    <table>
      <tr>[list;block=tr] <!-- block should always be merged with empty array onshow -->
        <td>[list.id]</td>
        <td>[list.name]</td>
        <td>[list.surname]</td>
        <td>[list.genre]</td>
      </tr>
      <tr>[list;block=tr;nodata]
        <td colspan="4"><p><em>Please wait while loading musicians...</em></p></td>
      </tr>
    </table>
  </div>
  <div id="pictures">
    <ul class="thumbnails">
      <li>[picture;block=li;p1=[musician.id]] <!-- block should always be merged with empty array onshow -->
        <img src="[picture.path]" alt="[picture.title"] />
      </li>
      <li class="nodata"><p><em>Please wait while loading pictures...</em></p></li>
    </ul>
  </div>
  <div id="detail">
    <!-- regular merged data -->
    <form method="post" action="[var._SERVER.REQUEST_URI]">
      <ol>
        <li><label>Name:</label> <input type="text" name="name" value="[musician.genre;noerr]" /></li>
        <li><label>Surname:</label> <input type="text" name="surname"  value="[musician.genre;noerr]" /></li>
        <li><label>Genre:</label> <input type="text" name="genre" value="[musician.genre;noerr]" /></li>
        <li><input type="submit" value="Save" /></li>
      </ol>
    </form>
  </div>
</div>
PHP:
$tbs->loadTemplate($template);

//(select musician from database into $musician)
$musician=array('id'=>1, 'name'=>'Foo', 'surname'=>'Bar', 'genre'=>'FooBar');

$tbs->mergeblock('list,pictures', array()); //<-- can this be done automatically just by some template-parameter for those blocks?
$tbs->mergefield('musician', $musician);

Is it possible to add some onformat or such to process the blocks with a special parameter before show to not need to merge the blocks manually with an empty array?

Thanks for any tips
Rudy
By: Skrol29
Date: 2010-04-05
Time: 22:20

Re: Automatically merge block with empty array before/onShow

Hi Rudy,

I can see at least 2 solutions.

1st solution:
Use property Assiged to prepare the blocks to be merged automatically on the OnShow event.
See http://tinybutstrong.com/forum.php?msg_id=10440#

2st solution:
Define onshow conditional blocks that have the same bounds that the blocks to delete. And use a conditional expression that is always false in order to have the blocks deleted in any case.
Example:
<table>
  <tr>[list;block=tr][onshow;block=tr+tr;when 0=1]
    <!-- block should always be merged with empty array onshow -->
    <td>[list.id]</td>
    <td>[list.name]</td>
    <td>[list.surname]</td>
    <td>[list.genre]</td>
  </tr>
  <tr>[list;block=tr;nodata]
    <td colspan="4"><p><em>Please wait while loading musicians...</em></p></td>
  </tr>
</table>

By: Rudy
Date: 2010-04-05
Time: 22:36

Re: Automatically merge block with empty array before/onShow

Hi Skrol29,

thanks for your reply. I use assigned a lot, but it would not make any difference assigning them or merging them with an empty array, both solutions need changes to the PHP code when new blocks are added.

Your second solution looks promising, but i see one problem: when ajax merges the block "list" the [onshow;.. directives will be multiplied along the rows and the result will be empty (the external script needs a "$tbs->show()" too and can't just output $tbs->Source)

Is it possible to delete the [onshow;block=tr+tr;when 0=1] during the mergeblock of "list"?