Categories > TinyButStrong general >

template driven merge

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: Anonymous
Date: 2009-05-13
Time: 12:24

template driven merge

Hi,
I would like allow the template user to do multiple independent merge on the same dataset withouth having to define on the php side how many such merge will there be.

In practice I would like to allow this
[scrb; block=div1; when [scrb.attr_tag]~='/R1/']
some other stuff here
[scrb; block=div2; when [scrb.attr_tag]~='/R2/']

This does what the manual says it should do, but I would like to have two independent merges here. Is there a way to achieve that? Maybe calling a script from the template which would create another block - I don't know.

Thanks for the help.
SWK
By: Skrol29
Date: 2009-05-14
Time: 11:06

Re: template driven merge

Hi,

Here is a trick that should work: save your data into a PHP array global variable (let's say $data), and do as if you where merging dynamic subblocks:
PHP
$TBS->MergeBlock('scrb','array','data'); // syntax for dynamic subblocks
HTML : use parameter p1 with any valid column to tell it is a new block.
  [scrb; block=div1; p1=attr_tag; when [scrb.attr_tag]~='/R1/']

  [scrb; block=div2; p1=attr_tag ;when [scrb.attr_tag]~='/R2/']

I'll see if such a feature can be added for the next TBS version.
By: Skrol29
Date: 2009-05-14
Time: 16:57

Re: template driven merge

Studying your case for a new feature, I'm discovering that there is a risk to provide a new parameter that allows multi block.

The risk is to use the feature to merge a large number of blocks that where previously multiplied by a MergBlock.
Example:
Let's say that TBS has a new parameter "newblock" which allows to define several blocks merged with the same name.
<tr>
   [article.name;block=tr]
   <select name="sel-country">
      <option> [country.name;block=option;newblock] </option>
   </select>
</tr>

In this configuration, the following code works but is very slow:
$TBS->MergeBlock('article',$article);
$TBS->MergeBlock('country',$country);

The good one is to chnage the order of the merges:
$TBS->MergeBlock('country',$country);
$TBS->MergeBlock('article',$article);